Process calendar items to send to Google Calendar

Hi, I’m pretty new to Make, and after studying all modules in the Make Academy I’ve spend half a day trying to solve a problem with processing collections in arrays in collections.

My goal is to read calendar items from Infinity and send them to (create them in) Google Calendar. The challenge is that the Infinity module does not always provide the item name in array element 1, start date in array element 2 and end date in array element 3. I have seen start date ending up in element 2, and with another calendar item in element 3.
Luckily the attribute id defines whether it’s the title or start date or end date that is contained in the array element.

Here’s the JSON that I created to test the scenario:
[
{
“id”: “c1”,
“values”: [
{
“data”: “Calendar item 1”,
“attribute_id”: “T”
},
{
“data”: “2025-02-23”,
“attribute_id”: “S”
},
{
“data”: “2025-03-01”,
“attribute_id”: “E”
}
]
},
{
“id”: “c2”,
“values”: [
{
“data”: “Calendar item 2”,
“attribute_id”: “T”
},
{
“data”: “2024-10-18”,
“attribute_id”: “E”
},
{
“data”: “2024-10-12”,
“attribute_id”: “S”
}
]
}
]

The blueprint attached shows a very simple scenario with just a Parse JSON module and a Set multiple variables module.
I have added nested IF statments to the value fields to determine the attribute type. Variable 1 (“Event”) should only be filled if the attribute id = T(itle), variable 2 (“Start date”) should only be filled if the attribute id = S(tart date), and variable 3 (“End date”) should only be filled if the attribute id = E(nd date).

However, all three variable are filled with the event title. I can’t see the cause of the error. Any help is much appreciated!
Please refer to the blueprint to see what’s happening.
blueprint.json (5.9 KB)

There are a couple of ways to do it, including using the map and get built-in functions.

But the easiest way that you can understand would be to use the toCollection function:

E.g.:

{{ toCollection(3.values; "attribute_id"; "data") }}

Screenshot_2024-06-22_000628

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

View Module Export Code

JSON

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 164,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "[\n{\n\"id\": \"c1\",\n\"values\": [\n{\n\"data\": \"Calendar item 1\",\n\"attribute_id\": \"T\"\n},\n{\n\"data\": \"2025-02-23\",\n\"attribute_id\": \"S\"\n},\n{\n\"data\": \"2025-03-01\",\n\"attribute_id\": \"E\"\n}\n]\n},\n{\n\"id\": \"c2\",\n\"values\": [\n{\n\"data\": \"Calendar item 2\",\n\"attribute_id\": \"T\"\n},\n{\n\"data\": \"2024-10-18\",\n\"attribute_id\": \"E\"\n},\n{\n\"data\": \"2024-10-12\",\n\"attribute_id\": \"S\"\n}\n]\n}\n]"
                    },
                    "metadata": {
                        "designer": {
                            "x": -2254,
                            "y": -1437
                        },
                        "restore": {
                            "parameters": {
                                "type": {
                                    "label": "Choose a data structure"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "type",
                                "type": "udt",
                                "label": "Data structure"
                            }
                        ],
                        "expect": [
                            {
                                "name": "json",
                                "type": "text",
                                "label": "JSON string",
                                "required": true
                            }
                        ]
                    }
                },
                {
                    "id": 166,
                    "module": "util:SetVariables",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "variables": [
                            {
                                "name": "id",
                                "value": "{{164.id}}"
                            },
                            {
                                "name": "attributes",
                                "value": "{{toCollection(164.values; \"attribute_id\"; \"data\")}}"
                            }
                        ],
                        "scope": "roundtrip"
                    },
                    "metadata": {
                        "designer": {
                            "x": -2064,
                            "y": -1437
                        },
                        "restore": {
                            "expect": {
                                "variables": {
                                    "items": [
                                        null,
                                        null
                                    ]
                                },
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "variables",
                                "type": "array",
                                "label": "Variables",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Variable name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Variable value",
                                        "type": "any"
                                    }
                                ]
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            }
                        ],
                        "interface": [
                            {
                                "name": "id",
                                "label": "id",
                                "type": "any"
                            },
                            {
                                "name": "attributes",
                                "label": "attributes",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

2 Likes

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too —

General

Help Center Basics

Articles & Videos

Partner & Custom Apps

samliewrequest private consultation

Join the unofficial Make Discord server to chat with other makers!

1 Like

Wonderfull! I added the toCollection function, and that does the trick!
Thanks!

2 Likes

No problem, glad I could help!

1. If anyone has a new question in the future, please start a new thread. This makes it easier for others with the same problem to search for the answers to specific questions, and you are more likely to receive help since newer questions are monitored closely.

2. The Make Community guidelines encourages users to try to mark helpful replies as solutions to help keep the Community organized.

This marks the topic as solved, so that:

  • others can save time when catching up with the latest activity here, and
  • allows others to quickly jump to the solution if they come across the same problem

To do this, simply click the checkbox at the bottom of the post that answers your question:
Screenshot_2023-10-04_161049

3. Don’t forget to like and bookmark this topic so you can get back to it easily in future!

4. Do join the unofficial Make Discord server for live chat and video assistance

samliewrequest private consultation

Join the unofficial Make Discord server to chat with other makers!

1 Like