Assigning user provisioning roles inside scripted decision node

Does anyone have an example of assigning a user role inside “scripted decision node”
A conventional method of setting attribute throws an error regarding incorrect format for “relationship” attribute type.

Here is an example another thing that I tried:
var myArray = new Array();
myArray.push(‘{“_ref”: “managed/alpha_role/myRoleName”}’);
var object = sharedState.get(“objectAttributes”)
object.roles = myArray;

Here is the error:
errorMessage=Invalid value format for relationship array



I think the problem is you need to JSON.parse() the value you’re pushing to the array.
I tested this:

try {
    objAttributes = sharedState.get("objectAttributes");
	objAttributes.put("roles", JSON.parse('[{"_ref":"managed/alpha_role/91677c5a-00bc-435a-8188-ca3c9d065a47"}]'))
    sharedState.put("objAttributes", objAttributes);
  outcome = "true"
} catch (e) {
  logger.error("DEBUG - ERROR: " + e)  
  outcome = "error"

And it works fine. I put a Patch Object Node right after this.

1 Like

This has worked perfectly. Thank you so much for your help