Code snippet : Find a workflow by name

vCenter Orchestrator references workflows by ID and allows to have multiple workflows with the same name. If the workflows you are calling have a unique name you can write a vCO wrapper to find a workflow by name with the following code.

Input: wfName (string)

Output: wfByName (Workflow)

var workflows = Server.findAllForType("Workflow", "c.name='"+wfName+"'");

var wfByName = null;

if (workflows != null){

 if (workflows.length == 1){

   System.log("Match found for workflow named: "+wfName);

   wfByName = workflows[0];

 }else{

   System.log("More than one VM found with that name! "+wfName);

   for each (wfl in workflows){

     System.log("Workflow ID: "+wfByName.id);

   }

 }

}
The interesting part is the second parameter of the findAllForType method : it is a query running on the server side, hence making the find a lot quicker than getting all the workflows and iterating through them to get the ones with the matching name.

Comments  

0 # DanielZilberman 2014-03-12 18:44
Very nice example of JavaScript that finds a workflow GUID by its name, thanks Christophe!

NUC Lab Kit

Below are my thoughts for a vSAN nuc lab. Since I already have cables, not including them here. I ordered (and received by Nov 30, 2016)
3 x nuc, 3 x 32GB Crucial mem, 3 x Toshiba NVMe drive, 3 x Startech USB to GB NIC, and 3 x Crucial 1TB SSD. I've also been very happy with my Cisco SG300-10 so I bought one more since my existing one only has one port available. Each of the items listed here are linked below - all were purchased using the provided links below.
single NIC (See this post for details on using the USB -> GB NIC item listed below

I stayed with the i5 for the power consumption and form factor vs. the i7 Skull Canyon ;)

 

Search

Experts Exchange