Skip to content

Workflow basics: inputs, outputs, and variables

A workflow holds data in three kinds of slot. Inputs are what the person or system running it supplies. Outputs are what it hands back when it finishes. Variables are its working memory in between. Each step in the schema reads some of these slots and writes others. Once that idea clicks, every other recipe in this chapter is a variation on it.

In this recipe you build a two-step workflow that takes a virtual machine, works out its power state, and returns a one-line summary of it.

Getting ready

  • A working Orchestrator login with a role that can create workflows, such as Workflow designer or administrator.
  • The vCenter registered in recipe 1.9 (vc01.vmw.lab), with at least one VM in its inventory.
  • A workflow folder for this chapter’s examples. Under Library > Workflows, switch to the folder (tree) view and create the folder VCF Orchestrator Guide, then a subfolder Chapter 3 inside it.
Needs a lab check. Check how folders are created in the 9.1.1 workflow library: the name of the view toggle, and whether you right-click a folder or use a New Folder button.

How to do it

Create the workflow

  1. Go to Library > Workflows and click New Workflow.
  2. Enter the name Describe a VM and click Create. The workflow editor opens on the Summary tab.
  3. On the Summary tab, set the folder to VCF Orchestrator Guide/Chapter 3 and add a short description, for example Returns the power state and size of one VM. Click Save.

Define the input and the output

  1. Open the Inputs/Outputs tab and click New. Add an input:
    • Name: vm
    • Type: VC:VirtualMachine
    • Direction: Input
  2. Click New again and add an output:
    • Name: summary
    • Type: string
    • Direction: Output

Define a variable

  1. Open the Variables tab, click New, and add a variable called powerState of type string. Leave its value empty. The first step fills it in.
Inputs/Outputs tab of Describe a VM: input vm of type VC:VirtualMachine, The VM to describe, used by Read power state and Build summary; output summary of type string, One line: name, power state, vCPUs and memory, used by Build summary.
Figure 3.1. The input and output of the Describe a VM workflow.

Add the first step

  1. Open the Schema tab. From the Generic group of the palette on the left, drag a Scriptable task onto the arrow between the start and end elements.
  2. Click the new element. In the properties pane on the right:
    • On the General tab, set Name to Read power state.
    • On the Inputs/Outputs tab, add vm as an input and powerState as an output.
    • On the Scripting tab, enter this script:
Describe a VM — Read power state
// vm is bound as an input, powerState as an output
powerState = vm.runtime.powerState.value;
System.log(vm.name + " is " + powerState);

Add the second step

  1. Drag a second Scriptable task onto the arrow between Read power state and the end element. Name it Build summary.
  2. On its Inputs/Outputs tab, add vm and powerState as inputs and summary as an output. Then enter this script:
Describe a VM — Build summary
var cpus = vm.summary.config.numCpu;
var memoryMb = vm.summary.config.memorySizeMB;
summary = vm.name + ": " + powerState + ", " + cpus + " vCPU, " + memoryMb + " MB";
System.log(summary);
  1. Click Save.
Schema tab of Describe a VM: Start, Read power state, Build summary, End. Build summary (item2, Scriptable task) is selected; its Inputs/Outputs section shows inputs vm (VC:VirtualMachine) and powerState (string) and output summary (string), each bound to the variable of the same name.
Figure 3.2. The finished schema, with the bindings of the second step.

Run it

  1. Click Run. The run form shows one field, vm, with a picker that browses the vCenter inventory. Choose any VM and click Run.
  2. When the run finishes, open its Logs tab. You see one line from each step.
  3. Open the run’s Variables tab. It shows the value of every input, variable, and output at the end of the run: the VM you chose, powerState (for example poweredOn), and the finished summary.
The run of Describe a VM, state Completed. The canvas shows Read power state and Build summary; the Variables tab lists powerState = poweredOn, vm, and summary = rockylinux9: poweredOn, 1 vCPU, 2048 MB.
Figure 3.3. A finished run, showing the values each slot held at the end.
Needs a lab check. Walk steps 1–14 on 9.1.1 and confirm the exact labels: New Workflow and Create, the Summary tab’s folder field, the Inputs/Outputs tab name (the 8.x docs call it both “Input/Output” and “Inputs/Outputs”), whether a parameter has a Direction column, the palette group Generic, and the scriptable task’s property tabs General, Inputs/Outputs, and Scripting.

How it works

The workflow editor’s tabs are the parts of one workflow definition. Summary holds its name, folder, description, and run settings. Variables and Inputs/Outputs declare its slots. Schema is the drawing of its steps, and Input Form (recipe 3.6) is the form people see when they run it. Version History and Audit record changes and runs.

When the workflow runs, Orchestrator creates a workflow token: one run, with its own copy of every slot. The inputs are filled from the run form, then the schema is walked from the start element. Before each step runs, Orchestrator copies the current values of that step’s bound inputs into it. After the step finishes, it copies the step’s outputs back into the slots they’re bound to. That copying is called binding, and it’s the only way data moves between steps. A variable you set in one scriptable task’s script isn’t visible in the next one unless it’s bound as an output of the first and an input of the second.

Inside a script, each bound slot appears as a plain JavaScript variable with the same name. That’s why the scripts above can use vm and powerState without declaring them, and why var cpus is local: it isn’t bound to anything, so it’s thrown away when the step ends.

The types matter. A binding only joins slots of compatible types, and the type decides what the run form offers. A VC:VirtualMachine input gets an inventory picker, while a string would get a text box. The VC: types come from the vSphere plug-in you configured in recipe 1.9.

Every token’s slots are saved to Orchestrator’s database after each step. That’s what makes the Variables tab of a finished run useful for troubleshooting, and it’s what lets a long workflow survive a restart and carry on where it stopped.

Each element is a checkpoint . If the server stops in the middle of a run, the run carries on from the element that was running, and that element starts again from its first line. There are no transactions and no rollback: whatever the element changed before the stop stays changed. Two things follow. Keep slots to simple values that can be saved, such as strings, numbers, Properties, inventory objects or a JSON string. And make each element safe to run twice: check before you create. A loop of elements on the canvas resumes at the item it was on; a loop inside one script starts again from the first item. Recipe 4.8 has more on both.

Back in vRO 5.5–7Edit workflows in the Java client. Workflow variables are called attributes, and you bind each element on its IN and OUT tabs, or by dragging lines in the Visual Binding tab.
In Orchestrator 9.xEdit workflows in the browser. Attributes are now called variables, and you bind each element on its Inputs/Outputs tab. There's no visual binding view.

There's more

Inputs are read-only. Inside the workflow, steps read inputs but don’t write them. If a step needs to change a value it was given, copy it into a variable and change that. Keeping inputs untouched also means the run’s Variables tab always shows what the person asked for.

Needs a lab check. Confirm that the 9.1.1 editor refuses to bind a step’s output to a workflow input parameter, and note what it shows when you try.

Variables with a value. A variable can have a starting value as well as a type, for example a default timeout or a vCenter folder name. Every run starts from that value. For values that change between environments, such as a mail relay or an IP range, a configuration element (Chapter 4) is a better home, because several workflows can share it and you can change it without editing them.

Inputs become the form. Every input appears on the run form, in the order you declared them, and every variable stays hidden. If something shouldn’t be asked of the person running the workflow, make it a variable. Recipe 3.6 shows how to group, label, and validate the form.

Name slots for what they hold. vm, powerState, and summary read well in scripts and in run logs. Avoid names such as input1 or temp. You’ll see them again in the Variables tab of a failed run at 2 a.m.

Outputs and other callers. Outputs matter most when something else runs the workflow: a parent workflow (recipe 3.2), a VCF Automation extensibility subscription, or a REST client. They get the output values back and you don’t need to parse logs.

See also