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.
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:
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.
I had the same problem and found this thread helpful, and thought I would add what I came up with. I used a Text Aggregator to join my JSON blocks, which already had the trailing comma built-in (although you could use a comma as a separator in the Text Aggregator), and then did a Set Variable module with the following:
substring(myString;0;length(myString)-1)
where the “-” has to be the mathematical function (noting because I did not do this at first), to remove my trailing comma.