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:

  1. Create a workflow with a string input (vmString) and a VC:VirtualMachine output (vmObject).
  2. Add a scriptable task and connect the in- and output parameter.
  3. In the script, enter the following code:
          query = "xpath:name='" + vmString + "'"; 
          vms=Server.findAllForType("VC:VirtualMachine", query); 
          vmObject=vms[0]; 
    
  4. 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.