Turning strings into objects
In this recipe, we will take a quick look at how to turn a string into an Orchestrator object (such as VC:VirtualMachine
). This technique is rather important when you use REST to start workflows.
Getting ready
We only need the Orchestrator Client with the right to create a workflow.
How to do it...
In this example, we turn a string into VC:VirtualMachine
:
- Create a workflow with a string input (
vmString
) and aVC:VirtualMachine
output (vmObject
). - Add a scriptable task and connect the in- and output parameter.
- In the script, enter the following code:
query = "xpath:name='" + vmString + "'"; vms=Server.findAllForType("VC:VirtualMachine", query); vmObject=vms[0];
- Run the workflow and enter a Virtual Machine name. ...
Get VMware vRealize Orchestrator Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.