Automatically Log Task and Action Names in Big Workflows

Log a start and end message in every scriptable task so a failed run points straight to the broken step. System.currentWorkflowItem() keeps the task names in those logs correct, even after you rename the tasks.

In this article

Orchestrator workflows can get huge for big jobs like hardware deployments or tenant provisioning, and they often call other workflows too. When one of them fails, finding the exact scriptable task that broke can take a while. Here’s a small logging habit that helps, and a trick that keeps the log messages correct even when you rename your tasks.

Tested on: VCF Operations Orchestrator 9.1.1 (Nov 2026) and vRealize Orchestrator 8.x (original post, 2022).

The problem

For debugging, most of us rely on System.log() or System.debug() to see what happened up to a point. I go one step further and log a start and an end message in every scriptable task. If a task starts but never logs its end message, I know exactly where the workflow broke.

For example, in a Create a VM workflow with a scriptable task called Get All VM Names, I’d add this at the top of the script:

System.log("\"Get All VM Names\" script started");

And this at the end:

System.log("\"Get All VM Names\" script completed");

This really helps in a big workflow, but it has one annoying problem. When you change what a task does and rename it, say from Get All VM Names to Get All VM Names and IPs, you also have to update both log lines. And that’s easy to forget.

The solution

I found a neat way around this on the VMware community forum: System.currentWorkflowItem() returns the item that’s running right now, so the script can read its own name.

In scriptable tasks

System.log("\"" + System.currentWorkflowItem().getDisplayName() + "\" script started");
System.log("\"" + System.currentWorkflowItem().getDisplayName() + "\" script completed");

This always logs the current name of the scriptable task, so you can rename it as often as you like.

Workflow logs showing the scriptable task name in the start and completed messages

If you also want the item number (like item1), use this:

System.currentWorkflowItem().getName();

In actions (optional)

This one is a little tricky. An action doesn’t have its own name on the canvas, but when you add it to a workflow, it becomes an item with a name and an item number. So the same trick logs the name of the workflow item that called the action:

if (System.currentWorkflowItem().getDisplayName())
    System.log("\"" + System.currentWorkflowItem().getDisplayName() + "\" action started");
if (System.currentWorkflowItem().getDisplayName())
    System.log("\"" + System.currentWorkflowItem().getDisplayName() + "\" action ended");
Start and end log lines added to an action script
Workflow logs showing the start and end messages from the action

The if check is there for when you run the action on its own. Then there’s no workflow item, the display name is empty, and nothing is logged, instead of a confusing "" action started.

Running the action on its own, with no start or end message in the logs

Extras

A few more ways to get details about the workflow from inside a script. I ran these on 9.1.1 and fixed a couple of lines from the original version that no longer return anything:

System.log("Workflow name: " + workflow.currentWorkflow.name);
System.log("Token name: " + workflow.name);
System.log("Root workflow name: " + workflow.rootWorkflow.name); // differs from currentWorkflow in nested workflows
var wfInstance = Server.getWorkflowWithId(workflow.currentWorkflow.id);
System.log("Path: " + wfInstance.workflowCategory.path + "/" + wfInstance.name);
System.log("Current item: " + System.currentWorkflowItem().getName()); // item1
System.log("First item: " + wfInstance.firstItem);

System.log("*** List of items in the workflow");
for (var i = 0; i < wfInstance.items.length; i++) {
    System.log(wfInstance.items[i].name); // End, Get All VM Names, ...
}

System.log("*** List of attributes in the workflow");
for (var j = 0; j < wfInstance.attributes.length; j++) {
    System.log(wfInstance.attributes[j].name);
}

Things to watch out for

  • Spelling matters. It’s firstItem, not firstitem. The lowercase version just returns undefined, with no error.
  • Call it as a function. System.currentWorkflowItem without the brackets doesn’t give you the item, so System.currentWorkflowItem.itemName is always undefined.
  • Nested workflows. workflow.currentWorkflow is the workflow that’s running the script, while workflow.rootWorkflow is the one at the top. In a simple workflow, they’re the same.

Wrapping up

It’s a tiny change, but with start and end messages in every task, a failed run in a big workflow points you straight to the right place, and renaming tasks no longer breaks your logs. See you in the next post.


Discover more from Cloud Blogger

Subscribe to get the latest posts sent to your email.

Enjoyed this post?

Was this helpful?

3 responses to “Automatically Log Task and Action Names in Big Workflows”

  1. Teknik Industri Avatar

    What are some best practices for managing logs in extensive workflows that utilize scriptable tasks?

    1. Mayank Goyal Avatar

      I would say the classic System.log() would do the job. Just afraid them to use as much as want. However, you can also consider the LogMarker class https://cloudblogger.co.in/2023/03/23/vro-logmarker-better-than-logger-action/

Leave a Reply