Introduction
It’s quite evident that vRO Workflows can grow huge for major provisioning tasks like hardware deployments, vApp deployments or tenant provisioning etc. just to name a few. And in a big environment, such workflows can come in large numbers and may be coupled with various other workflows quite generally for eg. using Nested WFs.
Concern
Now, the real pain starts when you have to debug them. for Debugging, developers relies mostly on System.log() or System.debug() to know about the statuses and variable values etc. up to a particular point, which is really great.
If I talk about myself, I even uses a start and completion log for every Scriptable task in a workflow. This always pinpoints to the scriptable task that was started but couldn’t complete due to any reason and therefore couldn’t print the end log. Let me explain it. There is a workflow (Create a VM) and there is a scriptable task (Get All VM Names). In this scriptable task, I would add some thing like
System.log("\"Get all VM Names\" script started");
JavaScriptand at the end of this script
System.log("\"Get all VM Names\" script completed");
JavaScriptImagine this in a very large workflow, this can really help. But I knew this needs to be improved. Sometimes, you changes the content of a scriptable task and its definition changes, so update it’s name -> Get All VM Names to Get All VM Names and IPs. In such cases, you have to update those start and end log statements. And I hate that!
Possible Solution
I referred to the vRO community (link) and found one interesting way out.
FOR WORKFLOWS
We can use this,
System.log("\""+System.currentWorkflowItem().getDisplayName()+"\" script started");
System.log("\""+System.currentWorkflowItem().getDisplayName()+"\" script completed");
JavaScriptThis will automatically print the updated name of the scriptable task.

You can also print the item#
if you want, using this command
System.currentWorkflowItem().getName();
JavaScriptFOR ACTIONS (OPTIONAL)
Now, this is a little tricky. We can’t do the same for actions. However, if we consider them as a part of a workflow, which means they will act similarly as an item and obviously will have a item number, then we can print their start and end cycle. We can do so by adding the below mentioned script in your actions.
if(System.currentWorkflowItem().getDisplayName())
System.log("\"" + System.currentWorkflowItem().getDisplayName() + "\" action started");
if(System.currentWorkflowItem().getDisplayName())
System.log("\"" + System.currentWorkflowItem().getDisplayName() + "\" action ended");
JavaScript

Here, we added a condition just to avoid printing if you try to run your actions solely.Ended "" script

Extras
How to get some information related to workflow items inside the workflow itself.
System.log("TokenName: "+workflow.currentWorkflow.name); -> Workflow Name
System.log("TokenName: "+workflow.name); -> Token Name
System.log("WorkflowName: "+workflow.rootWorkflow.name); -> Workflow Name
var wfInstance = Server.getWorkflowWithId(workflow.currentWorkflow.id);
System.log(wfInstance.workflowCategory.path +"/"+wfInstance.name); -> Workflow Path/Workflow Name
System.log(System.currentWorkflowItem.itemName);
System.log("WorkflowObject: "+wfInstance); -> Workflow type object
System.log("WorkflowFirstItem: "+wfInstance.firstitem);
System.log("*** List of items in Workflow");
for (var i = 0; i < wfInstance.items.length; i++)
System.log(wfInstance.items[i].name); // End, Scriptable Task, Start, Scriptable Task #2
System.log("*** List of attributes in Workflow");
for (var i = 0; i < wfInstance.executions.length; i++){
if(i == 1){
for (var i = 0; i < wfInstance.executions[i].attributesStack.length; i++){
System.log(wfInstance.executions[i].attributesStack[i].name);
}
}
}
JavaScript
Leave a Reply