For Each Data Pill is always undefined inside Script

PaKe
Kilo Sage

Hey,

 

I want to set a flow variable via script with the value from a "For Each"-Item. When I use the data pill I retrieve the correct value. When I want to use a script I always retrive "undefined".

The "Set Flow Variables"-Action is inside the "For Each"-Loop.

 

Where is my problem?

 

PaKe_0-1748597825828.pngPaKe_1-1748597858774.png

 

19 REPLIES 19

@PaKe 

it should print ideally

Also are you using the correct flow variable where you are returning the value using return statement

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

The flow variable is correct.

When I am using this script, everything works 

PaKe_0-1748599880760.png

 

@PaKe 

you should be able to access that value of for each using inline script.

It should work fine provided the item you are accessing has value, if it doesn't it will give you undefined

See below working example, where I appended and printed the final flow variable

flow variable iterate and append for the for each.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yeah it is weird. On my PDI I used the same script and it worked

It can be wired solution, try to repair the Flow designer plugin once.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************