Build a array of ID's with Server Connect Action to repeat through in Library action

First of all, I have never created, edited or purposefully created an array outside of what Wappler does automagically for you. So I think the solution I am looking for would be using an array, but maybe there is a better way someone can suggest.

I am working on splitting larger server actions into smaller actions to make them reusable. My need is to build up an array of ID’s, from an insert/update action based on all te ID’s that were affected in the action. This can be 1 or many ID’s. Then in a library action use parameter array to repeat through these ID’s and perform other actions using them.

Why I think I need an array, is because the ID’s “received” form the API action could be 1 or more.

Hi.
Building an array of IDs is not possible without extensions like 🚀 RunJS 1.3.1.

If you are getting the list of IDs from inserts in a repeat, you can enable output of insert step, and send the repeat object itself as a param to the other library actions that you create.
If you are getting list of IDs from different sources, you can concatenate them into a single variable with a comma.

On the library action, you can just either always expect an array, or always expect a comma-separated-sting (single ID is also OK to consider as comma-separated).
Or, you can create two different inputs, one for aray and one for CSV/single value - and setup the code accordingly.

Let me know if I am completely off the point, and you are talking about something else. This is what I have understood. :sweat_smile:

1 Like

Hi, Marcel!

Can you show what initial data that you get?

As I understand, you have a repeat, and inside of it you make insert to base? In that case you get an array of objects, and each object has some properties, one of them “id”. And you want to transform it into a simple array like [7, 11, 17, 19, 23]. Am I right?

In that case you just use the “flatten” formatter to the initial array. It’s description says “Flatten a property values and make an array from it”.

In formatter settings you have to set needed property in it. Something like this
myArrayName.flatten('insertRecord.identity')

1 Like

Thanks for the reply - I have just moved on to another module in the app, and will return to this in a week or 2. Will give feedback and see how I can improve then.

For now I just split my actions into one that handles a single var input and one that handles multiple using a repeat after a query action.