Is a double-Iterator required here? Seeking workaround

I’m using Wrike’s api to pull a variety of data centred around timelogs and disbursements. The output invariably produces bundles with an array of collections. I have been successful iterating through the bundles and aggregating into JSON structures to carry data through the scenario.

My problem is that sometimes there are nested arrays with collections in them that I need to pull data from, which must be associated with a given parent ID. See the example structure below:

In this case, I want the value associated with the id ending “YTS” (customFields.2) and have it appear in a JSON aggregation with disbursementId (the parent Id), disbursementName (title), and value (where customFields Id is …YTS). Note that

  • in some cases, there are a different number of collections in the customFields array (sometimes 1, sometimes >=3) and
  • I’m not confident they will always be in the same order. So referring to a child collection by index is not going to work (to my knowledge).

The only thing I’ve been successful in doing is using two back-to-back iterators to iterate through the parent, then the customFields array like this:

The problem is that this causes an enormous number of operations. I use this another time in my scenario. I’m worried that as my team uses Wrike, there could be 5000 operations or more in a given execution. I am working to add filters to different GET requests, but this is really going to be difficult to manage.

Is there an in-line solution - perhaps a way to use the map function to access these records - programmatically?

Many thanks for your time and attention.

Hi Conor - welcome to the Community!

I think your hunch is right - a map() function should be the way to go.

You’d need an Iterator to iterate through the data[] array. You’d follow that with a Set a variable module to extract the correct value from the customfields[] array.

The value of that variable should be something like:
get(map(X.customFields; value; id; IEAGJC4JJUAHKYTS); 1)

X is the module number of your Iterator. That will create an array with all the customFields values that match your chosen id. As there should only be one, you just want the first element in the array - that’s what the get() function does here.

You’d then follow that with an Array Aggregator including the parent id and the title from the Iterator, as well as the value of the variable from your Set a variable module.

Let us know how you get on!

Hello! Thank you for your prompt reply!

I have tried this before but always end up with an error indicating customFields is not a valid array. Indeed, it is an array of collections.

image

I’ll also add that this consumes a number of operations equivalent to the number of collections being iterated through at the parent level. In this case, it consumed 5 operations to load the variable. So it produces the same number of operations as the double-iterator. For reference, I will have pulled batches of possibly thousands of these records. We are just getting started with Wrike and I’m trying to design our invoicing system by pulling data out.

Any further suggestions would be appreciated!

If you’re on the Make Enterprise plan, the best answer would probably be to use a custom JavaScript function to transform the entire top level array.

But if not, there are a couple of other strategies:

  • JavaScript is available through the 0code app (which does require and additional paid service)
  • It may be possible to use Create JSON followed by a regex to transform into your desired array. But that’s going to be some complex regex - ChatGPT and Regex101.con are your friends here!