Iteration (PowerShell v2 target systems)
The Iteration
variable is available in Complex mappings. It is an integer that starts at 0 and counts how many times HelloID has run the JavaScript mapping function.
It becomes relevant when you're using the Uniqueness feature, and a complex target mapping generates a collision. When this happens, Iteration
is incremented and the complex mapping script is rerun.
It is also possible to specify a random or custom iteration value using $outputContext.Iteration in the uniqueness script. For example, you might want search the target system for the lowest unique number and return that. If you do so, that value will be used to retry the complex mapping, instead of a +1 increment.
To synchronize the iteration value across multiple fields, see Synchronize Unique Fields.
The maximum number of iterations (retries) per mapped field, per enforcement, is 50.
Typically, your JavaScript code in the complex mapping should convert Iteration
to a string and append it to the generated value (e.g., connie.van.den.winth
becomes connie.van.den.winth1
). For example:
function generateUsername() { if (!Person || !Person.Name){ return undefined; } const suffix = Iteration === 0 ? '' : Iteration; let maxAttributeLength = 20 - suffix.toString().length; let firstName = Person.Name.NickName; let middleName = Person.Name.FamilyNamePrefix; let lastName = Person.Name.FamilyName; let userName = firstName + '.'; //Check if the middleName variable contains data if (middleName) { userName = userName + middleName.replace(/\s+/g, '.') + '.'; } userName = userName + lastName; //Remove leading ... userName = userName.replace(/^\.+/, ""); //Convert to lower case userName = userName.toLowerCase(); //Remove diacritical chars userName = deleteDiacriticalMarks(userName); //Remove specific chars userName = userName.replace(/[^0-9a-zA-Z.]/g, ''); //Shorten string to maxAttributeLength minus iteration length userName = userName.trim().substring(0, maxAttributeLength) + suffix; //Remove tailing ... userName = userName.replace(/\.+$/, ""); return userName; } generateUsername();