12 Dec 2022
01:27 AM
- last edited on
20 Apr 2023
12: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.
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)
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
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.
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);
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);
^^^^^^
Thanks , Now I am able to access Object attributes as well.
The loop list must be a valid Python syntax, for example
[{"Country": "India", "Code": "100"}, {"Country": "USA", "Code": "200"}]
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)
Hey I am able to do that , I am good for now
Featured Posts