How to add values to an array within a repeater

I am trying to populate an array with values from a http request using a repeater

in short
I initialize a new array, run the http requests 3 times and use add() to add the values from the http request into the array, I then exit the repeater if i = 3 using a filter
and when I use getvariable to show the array after the filter it only contain one value, the last one.

something like this

Module 29: SetVariable
namemyarray
value EmptyArray

Module2: repeater
repeats 3 times

Module3: http
gets three different urls

Module set variable
name: myarray
value {{add(29.myarray; 28.data.SKU)}}

Module: filter
exit repeater exits if i eq 3

Module: getVariable myarray
returns only last item

what am I doing wrong?

Welcome to the Make community!

To allow others to assist you with your scenario, please provide the following:

1. Relevant Screenshots

Could you please share screenshots of your scenario? Also include screenshots of any error messages, module configuration fields, and any filter settings. We need to see what you’re working with to give you the best advice.

You can upload images here using the Upload icon in the text editor:

2. Scenario Blueprint

Please export the scenario blueprint. Providing your scenario blueprint file will allow others to quickly recreate and see how you have set up the mappings in each module, and also allows us take screenshots or provide module exports of any solutions we have for you in return - this would greatly benefit you in implementing our suggestions as you can simply paste module exports back into your scenario editor!

To export your scenario blueprint, click the three dots at the bottom of the editor then choose ‘Export Blueprint’.

You can upload the file here by clicking on this button:

3. Output Bundles of Modules

Please provide the output bundles of each of the relevant modules by running the scenario (you can also get this without re-running your scenario from the History tab).

Click on the white speech bubbles on the top-right of each module and select “Download input/output bundles”.

A. Upload as a Text File

Save each bundle contents in a plain text editor (without formatting) as a bundle.txt file.

You can upload the file here by clicking on this button:

B. Insert as Formatted Code Block

If you are unable to upload files on this forum, alternatively you can paste the formatted bundles.
These are the two ways to format text so that it won’t be modified by the forum:

  • Method 1: Type code block manually

    Add three backticks ``` before and after the content/bundle, like this:

    ```
    content goes here
    ```

  • Method 2. Highlight and click the format button in the editor

Providing the input/output bundles will allow others to replicate what is going on in the scenario, especially if there are complex data structures (nested arrays and collections) or if external services are involved.

Sharing these details will make it easier for others to assist you.

I added a blueprint and image

repeater_with_variable.json (6.5 KB)

my problem is that the getvariable return only the last item in the array, 3

You need to Get the Variable before you can merge the “current” value of the array.

Otherwise, it is “reusing” the emptyarray BEFORE the Repeater module.

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

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

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":1,"module":"util:SetVariable2","version":1,"parameters":{},"mapper":{"name":"myarray","scope":"roundtrip","value":"{{emptyarray}}"},"metadata":{"designer":{"x":0,"y":0}}},{"id":2,"module":"builtin:BasicRepeater","version":1,"parameters":{},"mapper":{"start":"1","repeats":"5","step":"1"},"metadata":{"designer":{"x":300,"y":0}}},{"id":414,"module":"util:GetVariable2","version":1,"parameters":{},"mapper":{"name":"myarray"},"metadata":{"designer":{"x":600,"y":0}}},{"id":3,"module":"util:SetVariable2","version":1,"parameters":{},"mapper":{"name":"myarray","scope":"roundtrip","value":"{{add(414.myarray; 2.i)}}"},"metadata":{"designer":{"x":900,"y":0}}},{"id":4,"module":"util:GetVariable2","version":1,"parameters":{},"filter":{"name":"exit","conditions":[[{"a":"{{2.i}}","o":"number:equal","b":"5"}]]},"mapper":{"name":"myarray"},"metadata":{"designer":{"x":1200,"y":0}}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?

Hope this helps! Let me know if there are any further questions or issues.

— @samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

2 Likes

thanks, that worked!

2 Likes