Enumerate vRO Workflow Inputs into a JSON object

| 1 minute
VMware vRealize Orchestrator vRO JSON How-To vRealize Suite

Just this week I had to create a JSON object that contained all of the workflow input parameters and their respective values. While I can’t guarantee this is the best way to do it, it definitely works.

I’ve tried to keep the comments succinct so if you have any questions please ask.

Code

// Get all input parameters for the parent workflow
var inParamsArray = workflow.rootWorkflow.inParameters;

// Get all input parameters for the current workflow to search through later
var paramFinder = workflow.getInputParameters();

// Create a new object to store each of the input parameters as a key:value object
var paramsObjArray = new Object();

// Loop through each input parameter name from inParamsArray and lookup the value for each input
for (var i=0; i < inParamsArray.length; i++){
	var paramName = inParamsArray[i].name;
	var paramValue = paramFinder.get(paramName);
	paramsObjArray[paramName] = paramValue; // Create a new object inside paramsObjArray with the name 'paramName' and the value 'paramValue'
	}

// Convert the paramsObjArray object to JSON
var paramsJSON = JSON.stringify(paramsObjArray);

// Log JSON contents
System.log("Workflow inputs in JSON format: " + paramsJSON);

return paramsJSON;
Share this on:
About Stellios Williams
Technical Account Manager VMware
This is my personal tech related blog for anything private and public cloud - including homelabs! My postings are my own and don’t necessarily represent VMware’s positions, strategies or opinions. Any technical guidance or advice is given without warranty or consideration for your unique issues or circumstances.
Comments
comments powered by Disqus