Conditional iteration to Google Sheets

I have an iterator which iterates over an array of objects that look like this:

[
   {"field_id": "name", "value": "John"}, 
   {"field_id": "phone", "value": "0502221321"}, 
   {"field_id": "email_address", "value": "a@a.com"}
] 

For each such object, I want to first check if it’s a relevant field_id (let’s say only “name” and “phone” are relevant, and I don’t need “email_address”). Then for relevant objects, I want to populate a Google Sheet row so that “John” (i.e. value field of object where "field_id"="name") and “0502221321” (i.e. value field of object where "field_id"="phone") go into the appropriate columns (let’s say column A and B).

I’m stuck at the part between the iterator and how to conditionally select objects to go into the Google Sheets row.
If I simply choose “Add row” after the iterator - it will add a new row for each field (new row for “John”, new row for “0502221321”, etc.).

How can I select the correct value for each column in the Google Sheets?

In pseudo-code it would look like this:

for item in array:
    if item["field_id"] = "name":
        insert item["value"] into row A
    if item["field_id"] = "phone":
        insert item["value"] into row B

Don’t iterate and use this formula instead : get(map(array; "value"; "field_id"; "name"); 1)
I upload you an example with the blueprint, import it in a new scenario to look at it.


image

extract object.json (20.8 KB)

M@gic Integration

1 Like

Wow… so much I need to learn… much simpler and cleaner. Thanks so much!

1 Like

If you need, private message me , I can train you or give support. meanwhile enjoy the solution and analyse the formula.

An iterator uses an array, and in your example you had just 1 element in the array, albeit with 3 collections. So the iterator would iterate just once over the elements rather than iterating through each collection.

The get/map technique is very useful when looking through collections/objects for a specific item. the get(<expression>;1) can also be replaced with first(map(<expression>)) where first just chooses the first element of the returned array from map().

1 Like