imtrinity94
Enthusiast
Enthusiast

How to get the full path of running workflow?

Jump to solution

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

0 Kudos
2 Solutions

Accepted Solutions
imtrinity94
Enthusiast
Enthusiast

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);

                       }

}

View solution in original post

0 Kudos
eoinbyrne
Expert
Expert

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

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);

                       }

}

View solution in original post

0 Kudos
eoinbyrne
Expert
Expert

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

iiliev
VMware Employee
VMware Employee

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

Thanks eoinbyrne and 

 

Tags (1)
0 Kudos
imtrinity94
Enthusiast
Enthusiast

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)

0 Kudos