Wednesday Tidbit: Verifying a variable type in vRealize Orchestrator

Really short post, but this might stop you from going bat**** crazy…

Recently I needed to create some NSX Distributed Firewall Rules in vRealize Orchestrator for a complex micro-segmentation project. The layer 3 section already existed in NSX, I just needed to create the rules on the fly using the REST API.

If you’re familiar with the NSX API, you’ll know that to do this you need two things, the section ID and the eTag. So I created an API request to get both, and then pass the results to a scriptable task which would parse the results.

The first attempt looked like this:

var myXML = new XML(attContentAsString)
attNsxSectionId = myXML.section.@id;
System.log("NSX Section ID: " + attNsxSectionId);

attNsxEtag = attHeaders.get("ETag");
System.log("NSX eTag: " + attNsxEtag);

However whilst the logs showed the correct results for both variables, the section ID wasn’t actually passing the attribute correctly. So next task in the workflow obviously had issues.


In short even though my two variables were of type String, it appeared I was attempting to pass XML into attNsxSectionId. To verify this, I used the following:

var myXML = new XML(attContentAsString)
attNsxSectionId = myXML.section.@id;
System.log("The variable is of type: " + (typeof attNsxSectionId));

This quickly showed me where I was going wrong. It didn’t error, it just ignored it. Once I understood what was happening I converted the output to string using:

var myXML = new XML(attContentAsString)
attNsxSectionId = myXML.section.@id.toString();
System.log("NSX Section ID: " + attNsxSectionId);

Hope this helps!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.