Writing and reusing actions
Recipe 3.2 wrote a first action and called it from a workflow. Once you have a few dozen workflows, actions become the real library of your Orchestrator: the place where “get the facts about a VM” or “turn a size into a readable string” is written once and used everywhere. That only works if the actions are small, predictable, and safe to change.
In this recipe you build three actions in com.vcfguide.chapter4. getVmFacts collects a VM’s details into a Properties object. formatVmFacts turns those facts into one line of text. describeVm calls the other two. Then you change getVmFacts the safe way, look at its version history, and check who depends on it.
Getting ready
- The action module
com.vcfguide.chapter4from recipe 4.1. - The vCenter registered in recipe 1.9,
vc01.vmw.lab, with at least one VM. The actions only read from it.
How to do it
An action that gathers facts
- In Library > Actions, create the action
getVmFactsin the modulecom.vcfguide.chapter4. - On the General tab, set the Version to
1.0.0and add the descriptionReturns the name, power state, size, and guest OS of a VM as Properties. - On the Script tab, add one input,
vm, of typeVC:VirtualMachine, and set the Return type toProperties. Enter this script and click Save:
// Collects the facts most workflows need about one VM. Reads only.if (!vm) { throw "getVmFacts: the input vm is required";}var facts = new Properties();facts.put("name", vm.name);facts.put("powerState", vm.runtime.powerState.value);facts.put("cpus", vm.summary.config.numCpu);facts.put("memoryMb", vm.summary.config.memorySizeMB);facts.put("guestOs", vm.summary.config.guestFullName);return facts;- Click Run. Click in the
vmfield to open the Select VC:VirtualMachine dialog, open vSphere vCenter Server > your vCenter > Datacenters > your datacenter > vm down to the folder that holds the VM, tick the VM, and click Select. Click Run. The Last Run Details panel opens under the editor: on Result / Inputs, expand Action Result to see the five keys and their values, and Logs shows anything the action wrote. Drag the bar above the panel upward if the rows are cut off.

An action that formats them
- Create the action
formatVmFactsin the same module, with one inputfactsof typePropertiesand the return typestring:
// Turns the Properties from getVmFacts into one readable line.if (!facts || !facts.get("name")) { throw "formatVmFacts: facts must come from getVmFacts";}return facts.get("name") + ": " + facts.get("powerState") + ", " + facts.get("cpus") + " vCPU, " + facts.get("memoryMb") + " MB, " + facts.get("guestOs");An action that calls the other two
- Create the action
describeVm, with one inputvmof typeVC:VirtualMachineand the return typestring:
var chapter4 = System.getModule("com.vcfguide.chapter4");var facts = chapter4.getVmFacts(vm);var line = chapter4.formatVmFacts(facts);System.log(line);return line;- Run
describeVmwith a VM. The log and the result show one line, built by the two actions it called.
Change an action without breaking its callers
- Open
getVmFactsagain. Add a sixth fact after theguestOsline:
facts.put("host", vm.runtime.host ? vm.runtime.host.name : "");- On the General tab, change the Version to
1.1.0and click Save. Callers that only read the first five keys, such asformatVmFacts, carry on unchanged. - Open the Version History tab. A timeline on the left lists each saved version with its date, a short commit ID and the user who saved it, newest first, and a Restore link under every version except the current one. On the right, Selected Version is the current version and Diff against picks the one to compare it with. Choose
1.0.0to see the added line.
Version History tab of getVmFacts, versions 1.0.0 and 1.1.0 listed, the compare view open with the added facts.put("host", …) line highlighted.
Find out who uses an action
- Before you change an action’s inputs, rename it, or delete it, check what calls it. Open the action and click Find usages at the top of the editor.

The list covers both ways of calling an action. An action element on a schema shows as Workflow Schema : item1. A call from a script, written as System.getModule("com.vcfguide.chapter3").findVmsByName(...), shows as Scripting : item1, line 3, with the line number. Find dependencies, beside it, answers the opposite question: which actions this action calls. The REST API has the same lookup as GET /actions/{id}/dependencies.
How it works
An action is a JavaScript function with a name, typed inputs, and one typed return value, saved once in Orchestrator’s database. Its full name is its module plus its name, com.vcfguide.chapter4/getVmFacts. The module is only a namespace, written like a Java package, which keeps your actions apart from the hundreds that ship with Orchestrator and its plug-ins under com.vmware.library.
System.getModule("com.vcfguide.chapter4") returns an object whose methods are the module’s actions. Calling chapter4.getVmFacts(vm) runs that action straight away, in the same thread as the script that called it, and hands back its return value. The action can’t see the caller’s variables. It only sees its own inputs, which keeps it predictable.
Arguments are passed by position, in the order the inputs are declared on the action’s Script tab. The names don’t matter to the caller. That’s the one thing that makes changing an action risky:
- Adding a key to a returned
Properties, as in step 8, is safe. Callers ignore keys they don’t read. - Adding a new input at the end is fairly safe. Old callers pass nothing for it, so it arrives as
nullorundefined, and the action can fall back to a default. - Adding an input in the middle, reordering inputs, or changing a type silently breaks every caller that uses the old order.
- Renaming an action or moving it to another module breaks every script that calls it with
System.getModule, and can break action elements too. Check its references first, as in step 11.
The Version field is a label for people. Orchestrator doesn’t keep several callable versions side by side: every caller always gets the latest saved script. Raising the version tells the next reader, and the next package import (Chapter 6), that something changed. The Version History tab keeps the old scripts so you can see what changed and go back.
There's more
One job per action. Name actions with a verb and an object: getVmFacts, findVmsByName, formatVmFacts. If you can’t name an action without “and”, it’s two actions. Small actions are easier to test with Run, easier to reuse, and easier to fix.
Check inputs and fail loudly. A clear throw at the top of an action, as in steps 3 and 5, turns a confusing failure deep inside a workflow into a one-line message that says what was wrong. The caller’s exception path (recipe 3.4) receives that message.
Return Orchestrator types. Return a type that can be bound and stored with a run: a plug-in type, a string, a number, an Array/…, or Properties. The return type Any accepts anything, but it moves type checking from save time to run time, where it costs more. Keep it for actions that really return different things.
Don’t edit library actions. Actions under com.vmware.library belong to Orchestrator and its plug-ins, and an upgrade can replace them. If one is nearly right, copy its script into your own module and change the copy.
Actions in forms. Recipe 3.6 used actions to fill drop-downs and validate fields. Those run every time the form changes, so keep them fast and free of side effects. An action that writes something has no place behind a form.
Deleting an action. Check its references first. Through the REST API, DELETE /actions/{id} refuses an action that’s still referenced unless you add force=true, which leaves those workflows broken. Fix the callers first.
Moving actions between Orchestrators. You can export a single action to a file and import it elsewhere, but it’s easy to forget the actions it calls. A package (Chapter 6) carries an action together with everything it depends on.
See also
- 3.2 Scriptable tasks and the schema canvas, for action elements and Promote.
- 4.1 JavaScript in Orchestrator: the Rhino engine, for the API Explorer and the scripting objects.
- 4.3 Python actions and environments, for actions in another language.
- Broadcom TechDocs (Aria Automation Orchestrator 8.18): Create Actions in the Automation Orchestrator Client.
- VMware Docs (Aria Automation Orchestrator 8.13–8.14): Run an action and Version history.
- Broadcom developer documentation (VCF Operations Orchestrator API, latest): Create Action, Delete Action, and Action Dependencies.
- Broadcom KB: KB 421999.
- CloudBlogger, the author’s blog: Differences between vRO Workflows, vRO Actions, and vRA ABXs, How to create a custom JS class in vRO.
