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

Thanks

Hi,

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.

2 Likes

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

1 Like

@patryk - Thanks and this works well.

But in case user already has provisioning roles assigned, the above code remove all other roles and assigns this one.

I tried to get already assigned roles in array but still can not make it work.
Do you have any working snipet of code where user user already has a prov role assigned and another needs to be assigned in Scripted decision node?