How To
ForgeRock Identity Platform
Does not apply to Identity Cloud

How do I update attributes stored in arrays in IDM (All versions) using JavaScript?

Last updated Jan 12, 2023

The purpose of this article is to provide information on updating attributes stored in arrays in IDM using JavaScript® for the transform script. Attributes are stored in arrays when they need to be multi-valued.


Updating attributes stored in arrays

When an attribute is stored in an array, the transform script needs to iterate over the array and perform the replace on each array element.

For example, the following transform script will update an attribute of type string (single valued):

{ "source" : "manager", "target" : "manager", "transform" : { "type" : "text/javascript", "source" : "source.replace('ou=People,o=forgerock.com', 'ou=people,dc=forgerock,dc=com');" }

If the attribute is of type array (multi-valued), the transform script needs to iterate over the array and update each array element. The equivalent of the above script for a multi-valued attribute is as follows:

{ "source" : "manager", "target" : "manager", "transform" : { "type" : "text/javascript", "source" : "(function() { var numberOfMembers =source.length; for (var i = 0; i < numberOfMembers; i++) {source[i]=source[i].replace(/o=forgerock.com/i, \"dc=forgerock,dc=com\");}return source;}())" }

This transform script has been included in the sync.json file (located in the /path/to/idm/conf directory); alternatively, you could include this transform script in a separate file and call the file from sync.json instead, for example:

{ "source" : "manager", "target" : "manager", "transform" : { "type" : "text/javascript", "file" : "script/updateManager.js" }

See Also

How do I search managed user objects for attributes stored in arrays in IDM (All versions)?

Editing Connector Configuration Files

Related Training

N/A

Related Issue Tracker IDs

N/A


Copyright and Trademarks Copyright © 2023 ForgeRock, all rights reserved.