Enumerate vRO Workflow Inputs into a JSON object

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 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;
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy