VMware Cloud Community
imtrinity94
Enthusiast
Enthusiast
Jump to solution

How to get the full path of running workflow?

I wish to print the full Category path of currently running WF from inside its scripting element.


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
0 Kudos
2 Solutions

Accepted Solutions
imtrinity94
Enthusiast
Enthusiast
Jump to solution

var currentWFName = workflow.name  ;

var WFCategories = Server.getAllWorkflowCategories(); 

for each (var WFCategory in WFCategories){ 

     for each (var WF in WFCategory.allWorkflows){ 

if(WF.name == currentWFName){

System.log(WF.workflowCategory.path + "/" + WF.name);

                       }

}


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/

View solution in original post

0 Kudos
eoinbyrne
Expert
Expert
Jump to solution

Slightly improved / simplified version where we get the Server to do the lookup

var id = workflow.currentWorkflow.id;

var wfInstance = Server.getWorkflowWithId(id);

var catObj = wfInstance.workflowCategory;

System.log(catObj.path + "/" + wfInstance.name);

Should be a little quicker

View solution in original post

5 Replies
imtrinity94
Enthusiast
Enthusiast
Jump to solution

var currentWFName = workflow.name  ;

var WFCategories = Server.getAllWorkflowCategories(); 

for each (var WFCategory in WFCategories){ 

     for each (var WF in WFCategory.allWorkflows){ 

if(WF.name == currentWFName){

System.log(WF.workflowCategory.path + "/" + WF.name);

                       }

}


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
0 Kudos
eoinbyrne
Expert
Expert
Jump to solution

Slightly improved / simplified version where we get the Server to do the lookup

var id = workflow.currentWorkflow.id;

var wfInstance = Server.getWorkflowWithId(id);

var catObj = wfInstance.workflowCategory;

System.log(catObj.path + "/" + wfInstance.name);

Should be a little quicker

iiliev
VMware Employee
VMware Employee
Jump to solution

eoinbyrne​ - apart from being improved / simplified version, your code is also correct Smiley Happy, which is not the case for the code provided by imtrinity94

The problems in his code:

  • workflow.name does not return the workflow name but the workflow token name
  • it compares workflows by name, which doesn't work always; you can have multiple workflows with the same name in different categories
  • it is very inefficient as it iterates over all workflows in the vRO instance
imtrinity94
Enthusiast
Enthusiast
Jump to solution

Thanks eoinbyrne and 

 


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
Tags (1)
0 Kudos
imtrinity94
Enthusiast
Enthusiast
Jump to solution

iiliev Is there a way to get the workflow item name inside the same scriptable task? (For eg, item0 is a scriptable tasks with name = Rename a VM)


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
0 Kudos