# How can I access the "loop" variable in my workflow task?

**URL:** <https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652>\
**Category:** Developer Q&A Forum\
**Tags:** workflows\
**Created:** [December 12, 2022, 9:27am UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652 "2022-12-12T09:27:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dt\_martin](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@dt\_martin](https://community.dynatrace.com/u/dt_martin)\
**Post date:** [December 12, 2022, 9:27am UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652/1 "2022-12-12T09:27:42Z")

</div>

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&nbsp;{{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

---

<div class="post-metadata">

**Author:** ![michal\_zawislak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/michal_zawislak/32/13613_2.png) [@michal\_zawislak](https://community.dynatrace.com/u/michal_zawislak)\
**Post date:** [December 12, 2022, 10:27am UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652/2 "2022-12-12T10:27:31Z")

</div>

Hi Martin,  
To access loop variable with e.g. its name set to&nbsp;locations. You can access it like&nbsp;{{ \_.locations.lat }}&nbsp;(mind the&nbsp;\_.&nbsp;at the beginning)

 ![2022-12-12 11_27_08-Clipboard.png](https://global.discourse-cdn.com/dynatrace/original/2X/7/79d9add6375bf6e46eff6e2817c0181d53f1cca9.png)

![2022-12-12 11_34_10-Clipboard.png](https://global.discourse-cdn.com/dynatrace/original/1X/81784565c42f3a4e73a84f29c59b620d32725658.png)

---

<div class="post-metadata">

**Author:** ![heramb\_sawant](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@heramb\_sawant](https://community.dynatrace.com/u/heramb_sawant)\
**Post date:** [August 24, 2023, 6:54am UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652/3 "2023-08-24T06:54:19Z")

</div>

Hi ,&nbsp;  
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&nbsp; above example, but got an error in js code.  
console.log({{ \_.localtions.lat }});

Also ,is there&nbsp; a way to access the task loop counter inside task(JS code)??  
Regards,  
Heramb Sawant

---

<div class="post-metadata">

**Author:** ![michal\_zawislak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/michal_zawislak/32/13613_2.png) [@michal\_zawislak](https://community.dynatrace.com/u/michal_zawislak)\
**Post date:** [August 24, 2023, 7:30am UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652/4 "2023-08-24T07:30:04Z")

</div>

Hi Heramb,

To access the loop item in the “Run Javascript” task, I’d suggest using&nbsp;[automation-utils SDK](https://developer.dynatrace.com/reference/sdks/automation-utils/#action-execution-utilities-example)&nbsp;as it would be the simplest and fastest way.

 ![michal_zawislak_0-1692862045894.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/b/ebccffdeb943324fc2e7a6e7ba58d44f60b822fb.png)

 ![michal_zawislak_1-1692862056328.png](https://global.discourse-cdn.com/dynatrace/original/2X/c/cbee44a5230345b18a379e4820c244c353ef0016.png)

 ![michal_zawislak_2-1692862060439.png](https://global.discourse-cdn.com/dynatrace/original/3X/6/c/6c804b89d84c857c5d023286d1fac813ad649f11.png)

I hope this will help. If you have any more questions, don’t hesitate to reach out.

---

<div class="post-metadata">

**Author:** ![heramb\_sawant](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@heramb\_sawant](https://community.dynatrace.com/u/heramb_sawant)\
**Post date:** [August 25, 2023, 6:28am UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652/5 "2023-08-25T06:28:31Z")

</div>

Hey this works for me. I am able to access this Loop item values. I also tried string instead of integer like,&nbsp; item&nbsp; &nbsp;[‘USA’, 'UK].

Now I have little more addition. If&nbsp; I have item values like ,  
item&nbsp; [{ **Country** : ‘India’, **Code** : ‘100’} ,{ **Country** : ‘USA’, **Code** : ‘200’}]

How Can I access this Country and Code values in JS code?? I tried&nbsp; like below but got an error  
&nbsp; &nbsp; console.log(‘Loop item’ , actionExe.loopItem.Country);  
&nbsp; &nbsp; console.log(‘Loop item’ , actionExe.loopItem.Code);

---

<div class="post-metadata">

**Author:** ![michal\_zawislak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/michal_zawislak/32/13613_2.png) [@michal\_zawislak](https://community.dynatrace.com/u/michal_zawislak)\
**Post date:** [August 25, 2023, 6:53am UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652/6 "2023-08-25T06:53:48Z")

</div>

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”.

```auto
<span>console.log('Loop item' , actionExe.loopItem.item.Country);<br></span> ^^^^^^

```

---

<div class="post-metadata">

**Author:** ![heramb\_sawant](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@heramb\_sawant](https://community.dynatrace.com/u/heramb_sawant)\
**Post date:** [August 25, 2023, 8:01am UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652/7 "2023-08-25T08:01:43Z")

</div>

Thanks , Now I am able to access Object attributes as well.

---

<div class="post-metadata">

**Author:** ![michal\_zawislak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/michal_zawislak/32/13613_2.png) [@michal\_zawislak](https://community.dynatrace.com/u/michal_zawislak)\
**Post date:** [August 25, 2023, 8:04am UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652/8 "2023-08-25T08:04:29Z")

</div>

The loop list must be a valid Python syntax, for example

```auto
<span>[{"Country": "India", "Code": "100"}, {"Country": "USA", "Code": "200"}]</span>

```

---

<div class="post-metadata">

**Author:** ![heramb\_sawant](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@heramb\_sawant](https://community.dynatrace.com/u/heramb_sawant)\
**Post date:** [August 25, 2023, 8:39am UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652/9 "2023-08-25T08:39:31Z")

</div>

Yes I understood that now.

Hey I am not yet good with JS scripting 🙂&nbsp; 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)

 ![heramb_sawant_0-1692952608862.png](https://global.discourse-cdn.com/dynatrace/original/3X/9/3/93365bd66ac9d3fc4f8abe9c84767a96b47d43de.png)

---

<div class="post-metadata">

**Author:** ![heramb\_sawant](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@heramb\_sawant](https://community.dynatrace.com/u/heramb_sawant)\
**Post date:** [August 25, 2023, 8:53am UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652/10 "2023-08-25T08:53:03Z")

</div>

Hey I am able to do that , I am good for now

 ![heramb_sawant_0-1692953548113.png](https://global.discourse-cdn.com/dynatrace/original/3X/9/9/99278265e1f64d629be9fe085fa79fed600cee70.png)

---

<div class="post-metadata">

**Author:** ![avinashpodisett](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@avinashpodisett](https://community.dynatrace.com/u/avinashpodisett)\
**Post date:** [November 19, 2025, 6:24pm UTC](https://community.dynatrace.com/t/how-can-i-access-the-loop-variable-in-my-workflow-task/37652/11 "2025-11-19T18:24:15Z")

</div>

can we able to use loop item in DQL ?&nbsp;  
&nbsp;here is my usecase: first step is to load data from a lookup file, once data is retrieved, for every record, i need to make a DQL call to get metrics and if there is an anomaly, i need to create a problem ticket. kind of lookup functionality.
