VMware Cloud Community
domrein
Contributor
Contributor
Jump to solution

Foreach usage in Orchestrator 8.1

Hi Community,

sometimes I see somebody is using a foreach loop in Orchestrator Scripts.

As far as I know Javascript provides the foreach loop function.

I don't understand why Orchestrator doesn't "understand" my foreach?

What am I missing or doing wrong?

2020-06-29 18_10_44-127.0.1.11 - Remotedesktopverbindung.png

Regards

Dominik

1 Solution

Accepted Solutions
xian_
Expert
Expert
Jump to solution

What do you mean by "does not understand"?

Works as usual:

foreach.png

Maybe syntax highlighting is not right, but it works.

View solution in original post

Reply
0 Kudos
4 Replies
xian_
Expert
Expert
Jump to solution

What do you mean by "does not understand"?

Works as usual:

foreach.png

Maybe syntax highlighting is not right, but it works.

Reply
0 Kudos
lnairn
VMware Employee
VMware Employee
Jump to solution

Hi domrein​,

Your for each code is OK. I Think the issue is related to the vmNotes you has as  input parameter.... Can you do a System.log(vmNotes) and a System.log(vmNotes.keys), at the begining of the script task? To verify that the variable is a properties and has values.

Regards,

Leandro.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

It's not that vRO does not "understand" your code - if you run it, it should work just fine.

I think the problem is caused by the different Javascript engines used by vRO server to run the code and by Web client editor to validate the source code being edited. 'for each' itself is kind of deprecated in the newer Javascript engines (see, for example, https://developer.mozilla.org/en-US/docs/Archive/Web/JavaScript/for_each...in), and that's likely the reason why you get these syntax warnings in the UI.

I think something has been done about it in the upcoming 8.2, but right now I don't have a working 8.2 deployment at hand to confirm.

harshstar121
Contributor
Contributor
Jump to solution

Hi domrein

You can avoid those red marks from the code by just declaring the variable in the for-each loop.

pastedImage_2.png

Reply
0 Kudos