JavaScript in Orchestrator: the Rhino engine
Every JavaScript script you write in Orchestrator runs in Rhino, a JavaScript engine written in Java by the Mozilla project. That includes scriptable tasks, actions, scripted decisions, and the actions behind input forms. Rhino runs inside the Orchestrator server’s Java process, so your scripts can call Java objects as if they were JavaScript, and plug-ins can hand you objects such as a vCenter VM without any translation layer.
It also means the JavaScript you know from browsers and Node.js only partly applies. There’s no window, no setTimeout, no require, and no fetch, and some newer syntax may or may not be accepted. In this recipe you write a small action that asks the engine which features it supports, then you learn to look things up in the scripting API instead of guessing.
Getting ready
- A login with a role that can create actions, such as Workflow designer or administrator.
- An action module for this chapter,
com.vcfguide.chapter4. You create it in step 1.
How to do it
Ask the engine what it accepts
- Go to Library > Actions and click New Action. Enter the name
probeLanguageand the modulecom.vcfguide.chapter4, and click Create. - On the Script tab, leave the inputs empty and set the Return type to
Properties. - Enter this script and click Save. Each test is compiled separately by
evalinsidetry, so a feature the engine doesn’t know fails only its own test:
// Reports which newer JavaScript features this Orchestrator's Rhino engine accepts.// The script itself is plain ES5.1, so it runs on any version.var tests = [ ["let", "let a = 1; a"], ["const", "const b = 2; b"], ["arrow function", "(function () { var f = (x) => x * 2; return f(2); })()"], ["template literal", "var n = 3; `n is ${n}`"], ["default parameter", "(function (x = 5) { return x; })()"], ["for...of", "var s = 0; for (var v of [1, 2, 3]) { s += v; } s"], ["destructuring", "var o = { p: 1 }; var { p } = o; p"], ["spread", "Math.max(...[1, 2, 3])"], ["class", "(function () { class A {} return typeof A; })()"], ["Array.prototype.includes", "[1, 2, 3].includes(2)"], ["Object.assign", "Object.assign({}, { a: 1 }).a"], ["String.prototype.padStart", "'7'.padStart(3, '0')"]];var result = new Properties();for (var i = 0; i < tests.length; i++) { var name = tests[i][0]; try { var value = eval(tests[i][1]); result.put(name, "yes"); System.log("yes " + name + " -> " + value); } catch (e) { result.put(name, "no"); System.warn("no " + name + " (" + e + ")"); }}return result;- Click Run. The action has no inputs, so it starts at once, with no dialog. Open the Logs tab under the script: each feature has a
yesline or anowarning with the error the engine gave. The result shows the same answers as aPropertiesobject.

On Orchestrator 9.1.1 (build 25643527) the probe returns:
| Feature | 9.1.1 |
|---|---|
let, const |
yes |
| Arrow functions, template literals | yes |
Default parameters, for...of, destructuring |
yes |
Array.prototype.includes, Object.assign, String.prototype.padStart |
yes |
Spread (...) |
no: SyntaxError: syntax error |
class |
no: SyntaxError: identifier is a reserved word: class |
The Run button runs an action with no inputs straight away, without a dialog. The editor then shows Result / Inputs and Logs tabs under the script, and a Completed badge next to the action’s name.
Look things up in the API Explorer
- Open API Explorer, near the bottom of the navigation pane, below Deleted Items. Its tree has three branches: System (the built-in Objects, Enums and Types), Plugins (one entry per installed plug-in, such as VC or REST) and Actions (one entry per action module).
- Type
Systemin the Filter objects box, expand System > Objects and click System. The right side lists its methods, such aslog,warn,error,getModule,sleepandnextUUID, each with a one-line description, its parameters and its return type. The browser address now ends inexplorer?section=s&type=o&name=System, so you can bookmark the page. - Filter for
VcVirtualMachine, the scripting object behind theVC:VirtualMachinetype. It sits under Plugins > VC. Its properties includename,runtime, andsummary, which recipe 3.1 used to build a VM summary.

- Back in the editor of
probeLanguage, start a new line, typeSystem., and wait. Autocomplete lists the same methods. You don’t have to leave the editor to look something up: the Script tab has its own API Explorer panel beside the code, with the same tree and filter. The schema editor has one too, as the API Explorer tab of a scriptable task.
How it works
Rhino reads your script, compiles it, and runs it inside the vco-app server’s Java virtual machine. Before it runs, Orchestrator puts three kinds of name into the script’s scope: the bound inputs and outputs of the element (recipe 3.1), the built-in scripting objects such as System, Server, and Properties, and the objects of each plug-in, such as VcPlugin. Everything else is standard JavaScript: Math, Date, JSON, RegExp, arrays, and objects.
Which JavaScript that is depends on the Rhino version inside Orchestrator. Broadcom doesn’t publish it. Community reports give the versions below for older releases, and Rhino’s own compatibility table says what each one supports in general:
| Orchestrator | Rhino | What Rhino supports |
|---|---|---|
| 7.x and 8.x | 1.7R4 (reported) | ECMAScript 5.1 with a few extras such as let |
| 9.0 | 1.7.15 (reported) | Adds arrow functions, template literals, Array.prototype.includes, and more |
| 9.1.1 | 1.9.1 (measured in the lab) | Adds default parameters, for...of and destructuring, among others |
On the 9.1.1 lab, a test action logged Packages.org.mozilla.javascript.Context.getCurrentContext().getImplementationVersion() as Rhino 1.9.1, and getLanguageVersion() as 200, Rhino’s ES6 mode. The lab’s class shutter allowed the call; on a server with a stricter shutter (recipe 2.8), allow org.mozilla.javascript.Context first.
This book keeps every JavaScript sample to plain ES5.1: var, function, string concatenation, and loops with an index. Content often moves between Orchestrator versions, in packages, in Git, or in a VCF Automation upgrade, and an action that uses an arrow function works on one server and fails to compile on the next. ES5.1 runs everywhere.
Java under the surface. Plug-in objects are Java objects that Rhino wraps so they look like JavaScript ones. Most of the time you can’t tell. Sometimes a value that comes from Java behaves like an object rather than a JavaScript string, so a strict comparison with === fails or JSON.stringify gives something odd. When that happens, convert it first with String(value), or a number with Number(value). Scripts can’t create arbitrary Java objects. Only the classes in the class shutter file are allowed, as recipe 2.8 shows.
There's more
Use System.log, not console.log. A script’s log lines go to the run’s Logs tab through System.log, System.warn, System.error, and System.debug. Recipe 3.2 introduced them, and recipe 4.6 covers logging in depth.
No timers, no promises. A script runs from top to bottom and then ends. There’s no event loop to call you back later, so setTimeout doesn’t exist, and a promise never settles after the script ends. To wait, use the elements in recipe 3.7. To call an HTTP service, use the HTTP-REST plug-in (Chapter 5).
Properties or an object? Properties is Orchestrator’s own key–value type, backed by Java. Use it for inputs, outputs, and variables, because only Orchestrator types can be bound and saved with a run. Inside a script, a plain JavaScript object is often easier. Convert between them at the edges:
// props is a Properties variablevar obj = {};var keys = props.keys;for (var i = 0; i < keys.length; i++) { obj[keys[i]] = props.get(keys[i]);}
var back = new Properties();for (var key in obj) { if (obj.hasOwnProperty(key)) { back.put(key, obj[key]); }}Avoid Rhino’s own extensions. Rhino accepts some syntax that no other engine does, such as for each (var x in list). It works, but it ties the script to Rhino and confuses editors and linters. A plain for loop does the same job.
Write in an IDE, then import. If you’d rather write modern JavaScript or TypeScript in a code editor, VMware’s open-source Build Tools for VMware Aria compile it down to code Orchestrator accepts and package it for import. Chapter 6 covers moving content in and out of Orchestrator.
Test small pieces as actions. An action with no inputs, like probeLanguage, is the quickest place to try out a few lines. Action runs aren’t kept in the run history, so you can run them as often as you like without cluttering Activity > Workflow Runs.
See also
- 2.8 Setting system properties that matter, for the class shutter file.
- 4.2 Writing and reusing actions, to build actions that others can call.
- Broadcom TechDocs (Aria Automation Orchestrator 8.18): Create Actions in the Automation Orchestrator Client.
- VMware Docs (vRealize Orchestrator 8.9): Using the API Explorer.
- Broadcom Community: Why does Orchestrator use Mozilla Rhino instead of something more current? and Easier way to detect Rhino engine version.
- Mozilla: Rhino ES2015+ compatibility table.
- VMware type definitions for the scripting API: build-tools-for-vmware-aria, o11n-core.
- CloudBlogger, the author’s blog: Orchestrator Rhino Engine 8.x vs 9.x, A Brief Investigation of const in Orchestrator 9.1, Resolving TypeError: Cannot find function exec in Orchestrator 9.1.1, JavaScript to Java Conversion Limitation in vRO, Find Object Types in vRealize Orchestrator.
