Generate vRO Workflow Runs Report in CSV
Tags: article, tutorial, package, reporting
Published: 2022-04-13 13:12:17

---
title: Generate vRO Workflow Runs Report in CSV
published: true
date: 2022-04-05 10:09:25 UTC
tags: ARTICLE,Tutorial,Package,Reporting
canonical_url: https://cloudblogger.co.in/2022/04/05/generate-vro-workflow-runs-report-in-csv/
---

* * *

**<mark style="background-color:rgba(0, 0, 0, 0);">TL;DR</mark>** Download the package from [here](https://developer.vmware.com/web/dp/samples?id=7884) & edit the inputs and run it to get a CSV Report for last 30 days of Workflow Runs in vRealize Orchestrator.

* * *

Many a times, we have environments where we want to monitor the executions of vRealize Orchestrator Workflows, like how many times a workflow is run, who executed the workflow, or what was the success rate of a particular workflow, or maybe just want to check how long it take to execute a workflow. I have seen few customers that were looking for similar solutions. So, If you are also looking for a way to achieve something similar, this article could be of some help.

As we know, vRO offers REST API out-of-the-box for all kind of operations. Same is true for getting the facts and figures of its workflow execution. There are various ways to get that kind of information but I find using the **catalog-service-controller** module to be the quickest for my use-case. Let’s see it in detail below.

## **Understand the REST API**

The **catalog-service-controller** module is quite a versatile API module in vRO. You can use it to dig-in information for a extensive set of entities. However, the path and method we are mostly interested in today is, **GET /api/catalog/{namespace}/{type}**.

![](https://cloudblogger2021.files.wordpress.com/2022/04/image-5.png?w=1024)

### **Path with attributes**

```
/api/catalog/System/WorkflowToken?conditions=state%5Ecompleted%7Cfailed&conditions=endDate%3E"+date30DaysAgo+"&conditions=endDate%3C"+currentDate
```

where **_date30DaysAgo_** will get its value from _getDate30DaysAgo()_ action and **_currentDate_** from _getCurrentDateInISOFormat()_ action available in the [vro-package](https://github.com/vmwarecode/vRealize-Orchestrator-Reporting---Export-Workflow-Runs-to-CSV-and-Mail/blob/0d8a1a10d8678b141db3374b2e326594bb39c3bb/WorkflowRunReport.package).

* * *

**<mark style="background-color:rgba(0, 0, 0, 0);">Note</mark>** You can add more states to this query like **waiting** , **canceled** , etc. if you are interested in workflow tokens other than **completed** and **failed**.

* * *

## **Understand the Code**

In the package attached, we have a workflow **Workflow Runs Report Generation** which will have the code divided in 3 parts. For ease of operation, the workflow is creating a transient REST host using user provided inputs but you can also add your vRO as a REST Host in the inventory and add [this REST URL](https://cloudblogger.co.in/2022/04/05/generate-vro-workflow-runs-report-in-csv/#REST-URL) as a REST Operation with dates as variable input. Also, in Part 2/3, only 5 properties are added to the CSV data. You can lookup for additional properties related to a workflow token if you want a more details-heavy report.

```
//Part 1/3: Invoke Rest Operation
.
.
.

//Part 2/3: Gather data in CSV format
var reportCSV = "Name,Status,Start Date,End Date,Started by\r\n";
if (response.statusCode != 200) { // 200 - HTTP status OK
    System.warn("Request failed with status code " + response.statusCode);
} else {
    var doc = JSON.parse(response.contentAsString);
    System.log("Number of failed or cancelled tokens: " + doc.total);
    for each(var link in doc.link) {
        for each(var attribute in link.attributes) {
            if (attribute.name == "name")
                var wfName = attribute.value;
            if (attribute.name == "state")
                var wfState = attribute.value;
            if (attribute.name == "startDate")
                var wfStartDate = attribute.value;
            if (attribute.name == "endDate")
                var wfEndDate = attribute.value;
            if (attribute.name == "startedBy")
                var wfStartedBy = attribute.value;
        }
        reportCSV += (wfName + "," + wfState + "," + wfStartDate + "," + wfEndDate + "," + wfStartedBy+"\r\n");
    }
}

//Part 3/3: Send CSV data as a mail attachment
.
.
.
```

In Part 3/3, we are simply attaching the CSV data as a MIME attachment and send it to the **toAddress**.

## **Let’s Run it**

- Import the package available [here](https://github.com/vmwarecode/vRealize-Orchestrator-Reporting---Export-Workflow-Runs-to-CSV-and-Mail/blob/0d8a1a10d8678b141db3374b2e326594bb39c3bb/WorkflowRunReport.package). If you need help with package import, follow this guide [here](https://docs.vmware.com/en/vRealize-Orchestrator/8.0/com.vmware.vrealize.orchestrator-using-ops-client.doc/GUID-CE405299-1800-40C0-9054-5C032A5B022C.html).
- Go to workflow **Workflow Runs Report Generation** and Click **Edit** 
- Go to the scriptable task and edit these input values.

![](https://cloudblogger2021.files.wordpress.com/2022/04/image-6.png?w=486)

- After editing the values, **Save** it. 
- Click **Run**.

![](https://cloudblogger2021.files.wordpress.com/2022/04/image.png?w=1024)

- If the workflow executed successfully, you will see in the logs, the mail is being sent to the provided email address.

![](https://cloudblogger2021.files.wordpress.com/2022/04/image-1.png?w=1024)

- Check your mailbox. If you can’t see the email in your inbox, probably check the email address that you’ve provided or check your **SPAM** folder.

![](https://cloudblogger2021.files.wordpress.com/2022/04/image-2.png?w=1024)

- Download the attached CSV file and Open it. You will see a sheet which will be identical to what you have in your vRO **Workflow Runs** Tab _(Performance view OFF)_. You may also want to sort this sheet on **Start Date** column in descending manner.

![](https://cloudblogger2021.files.wordpress.com/2022/04/image-4.png?w=1024)

![](https://cloudblogger2021.files.wordpress.com/2022/04/image-3.png?w=725)

## **Download vRO Package**

[![](https://cloudblogger2021.files.wordpress.com/2022/01/92813512-27f0bb80-f376-11ea-8562-ee2b3e416aec-2.png?w=123)](https://github.com/vmwarecode/vRealize-Orchestrator-Reporting---Export-Workflow-Runs-to-CSV-and-Mail/blob/0d8a1a10d8678b141db3374b2e326594bb39c3bb/WorkflowRunReport.package)

* * *

That’s it in today’s post. I hope you will like it.