VMware Cloud Community
pengchen4
Contributor
Contributor

vRO workflow token can't get it's complex type attributes by invoking method WorkflowToken.getAttributes()

I have a workflow with a complex type attribute, default value was null for the attribute,  I want to run a script task to print current workflow token's attribute values by invoking method WorkflowToken.getAttributes(). Don't say to bind attribute with input/output parameter of script task than use the attribute directly, My objective is to create a generic action to do that thing. My script is:

var token = workflow;

System.debug(token);

if(token == null)

{

    throw "No workflow token found";

}


System.debug("startDate: " + token.startDate);


var attributes = token.getAttributes();

if(attributes == null || attributes.keys.length == 0)

{

    throw "No attribute found for current workflow.";

}

System.debug("found " + attributes.keys.length + " attributes from current workflow.");

var keys = attributes.keys;

for (var i in keys) {

    var curKey = keys[i];

    var curValue = attributes.get(curKey);

   System.debug("attribute key: " + curKey + " attribute value: " + curValue);

}

    System.debug("attribute key: " + curKey + " attribute value: " + curValue);

}

When I don't set value for the complex type attribute.

ComplexTypeNoValue.png

I could retrieve the attributes and get and null value of the complex type attribute.

Log.png

But once I set value of the complex attribute.

ComplexTypeWithValue.png

I got error when running the script task.

ErrorLog.png

I have tried many kinds of complex type, still get same error,I suspect if there's defect on vRO to retrieve complex type attributes from workflow token, or is there anything I missed? Can someone help me?

Tags (1)
Reply
0 Kudos
3 Replies
iiliev
VMware Employee
VMware Employee

Tried your script in my 6.0.3 and 7.0.1 environments - seems to work; the attribute was found no matter if it had assigned value or not.

Which vRO version/build do you use? Also, could you try if you have the same problem with already completed workflow tokens (ie. instead of using 'workflow' variable, select the token object as an input parameter).

Reply
0 Kudos
pengchen4
Contributor
Contributor

I was using VRO 6.0.3, thank you for your suggestion, but how can I make a completed workflow token as an input parameter?

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

Just add a new workflow input parameter and change its type from string to WorkflowToken

Reply
0 Kudos