Join variables and remove last trailing comma

Here’s the entire scenario, with notes on what certain modules do:

I hope I have explained it enough, I am stuck at the Get Variables stage where I need to combine the variables back together with a comma separator, but not the last one or if its a single variable.

Very much appreciate help on this.

Hey Max,

will all the variables be present every run? Or is it possible for some of them to be empty and thus, needing to be ignored in the final string?

Hi there, no it can vary, it could be one or multiple variables.

For context, each technician does a fire-safety assessment check of a business and prepares a quote of recommended items etc. So every job will differ in what they access from each product category: Fire alarms (data_FA), Fire Sprinklers (data_FS), Fire Doors (data_FS), Emergency Lighting (data_EL).

So empty ones should be ignored.

The Get Variables returns only the variables that have data - which is great:

I then updated the scenario to the following:

Which seems to work perfectly and create the required output I need, I was able to test it and it worked as expected. What are your thoughts on this approach?

Yeah, converting them to an array and then turning that in a comma separated list is a good approach.

You can also try replacing the iterator and the text aggregator with the join() function. It should do the same thing and save two operations. Then you can put that on top of the function to turn it in an array and move those directly in the HTTP module removing the need for the Set variable module as well.

2 Likes

Nice! yes that’s a perfect idea to reduce the operations down - thanks!