2 minutes
Javascript Limitations in vRealize Orchestrator 8.6
*[vRA]: vRealize Automation *[vRO]: vRealize Orchestrator One of the selling points for vRO is the ability to run JavaScript inside of a workflow using "Scriptable Tasks". With the release of vRA 8, was the addition of polyglot scripting. While this is a great development for the project, I would have much preferred them to implement modern JavaScript (ES6 +) instead.
As of vRealize Orchestrator 8.6, VMware is using ECMAScript 5.1 and this comes with quite a few limitations for those who are used to the features of modern JS.
Things that work in vRO
Create a constant object
const student = {
name: 'Harry Potter',
house: 'Gryffindor',
address: {
streetNumber: 4,
streetName: 'Privet Drive',
confirmed: true,
},
};
Build a function
function sendLetterIfConfirmed(student) {
if (!student.address || !student.address.confirmed) return;
System.log(
'Sending welcome letter to ' +
student.name +
' at ' +
student.address.streetNumber +
' ' +
student.address.streetName
);
}
sendLetterIfConfirmed(student);
Assign multiple variables at once
const colors = ['red', 'green', 'blue'];
var [x, y, z, a] = colors;
System.log(x); //red
System.log(y); //green
System.log(z); //blue
System.log(a); //undefined
Do/While loop
var count = 0;
do {
count++;
System.log('count is:' + count);
} while (count < 10);
For loop
for (var counter = 1; counter < 5; counter++) {
System.log('Inside the loop:' + counter);
}
System.log('Outside the loop:' + counter);
Labels
var iterations = 0;
top: for (var i = 0; i < 5; i++) {
for (var j = 0; j < 5; j++) {
iterations++;
if (i === 2 && j === 2) {
break top;
}
}
}
System.log(iterations); // 13
Ternary operator
var age = 19;
var canDrive = age > 16 ? 'yes' : 'no';
System.log(canDrive); // yes
isArray
var seas = ['Black Sea', 'Caribbean Sea', 'North Sea', 'Baltic Sea'];
var index = seas.indexOf('North Sea');
System.log(Array.isArray(seas)); // true
Sort
var employees = [
{
firstName: 'John',
lastName: 'Doe',
age: 27,
joinedDate: 'December 15, 2017',
},
{
firstName: 'Ana',
lastName: 'Rosy',
age: 25,
joinedDate: 'January 15, 2019',
},
{
firstName: 'Zion',
lastName: 'Albert',
age: 30,
joinedDate: 'February 15, 2011',
},
];
System.log(employees.sort);
Things that do not work in vRO as of 8.5
Now here are some things that you might expect to work in vRO, but will return validation errors.
Let
let x = 10; //This one makes sense as scope is already defined
.includes
const colors = ['red', 'green', 'blue'];
const result = colors.includes('red');
Using backticks ``
System.log(`This would have been nice: ${variable}`);
Optional Chaining
if (!student.address?.confirmed) return;
Spread Operator
const copyOfStudent = { ...student };
padStart
var number = 4;
System.log(number.padStart(2, 0));