12 Dec 2022 09:27 AM - last edited on 20 Apr 2023 08:56 AM by educampver
Hello team,
I have a workflow action where I want to loop over an array of locations (lat, long)
I named the item variable "locations" and the list would look something like this.
[{lat: 48.29226713, long: 14.29553878}]
How can I access these values in my HTTP Request?
EDIT: I have tried writing {{locations.lat}} but it doesn't seem to work this way.
EDIT_2: Figured out that my value for the list was malformed (invalid json). Using [{ "lat": 48.29226713, "long": 14.29553878}] works but still don't know who to read those values
Solved! Go to Solution.
12 Dec 2022 10:27 AM - edited 12 Dec 2022 10:35 AM
Hi Martin,
To access loop variable with e.g. its name set to locations. You can access it like {{ _.locations.lat }} (mind the _. at the beginning)
24 Aug 2023 07:54 AM - edited 24 Aug 2023 08:04 AM
Hi ,
I want to do the same thing but in my case task is JS code. So How I can access this loop variable (added to my js code task) in my js code, how should be the syntax, please help.
I referred above example, but got an error in js code.
console.log({{ _.localtions.lat }});
Also ,is there a way to access the task loop counter inside task(JS code)??
Regards,
Heramb Sawant
24 Aug 2023 08:30 AM
Hi Heramb,
To access the loop item in the "Run Javascript" task, I'd suggest using automation-utils SDK as it would be the simplest and fastest way.
I hope this will help. If you have any more questions, don't hesitate to reach out.
25 Aug 2023 07:28 AM
Hey this works for me. I am able to access this Loop item values. I also tried string instead of integer like, item ['USA', 'UK].
Now I have little more addition. If I have item values like ,
item [{Country : 'India', Code: '100'} ,{Country : 'USA', Code: '200'}]
How Can I access this Country and Code values in JS code?? I tried like below but got an error
console.log('Loop item' , actionExe.loopItem.Country);
console.log('Loop item' , actionExe.loopItem.Code);
25 Aug 2023 07:53 AM
Glad it works!
Yes, you can also access object attributes. Your example is almost correct. There's a little thing missing: a reference to the "loop item".
console.log('Loop item' , actionExe.loopItem.item.Country);
^^^^^^
25 Aug 2023 09:01 AM - edited 25 Aug 2023 09:08 AM
Thanks , Now I am able to access Object attributes as well.
25 Aug 2023 09:04 AM - edited 25 Aug 2023 09:07 AM
The loop list must be a valid Python syntax, for example
[{"Country": "India", "Code": "100"}, {"Country": "USA", "Code": "200"}]
25 Aug 2023 09:39 AM
Yes I understood that now.
Hey I am not yet good with JS scripting 🙂 Can I write the same JS code(code to access item object attributes) in standard JS code user task ( please refer below image for the same)
25 Aug 2023 09:53 AM
Hey I am able to do that , I am good for now