imtrinity94
Contributor
Contributor

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
1 Solution

Accepted Solutions
imtrinity94
Contributor
Contributor

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
3 Replies
imtrinity94
Contributor
Contributor

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

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
0 Kudos