Skip to main content

HelloID

Complex target mappings (Azure AD target systems)

HelloID supports JavaScript for complex mappings. Use them to transform or format mapped user attributes using custom JavaScript code. Complex mappings support the ECMAScript 5.1 standard.

Use the Person object to access fields in the current person. The properties of this object correspond to the fields in the Person schema. For example, a person's first name may be available at Person.Name.GivenName. Do not attempt to initialize or overwrite these properties.

Complex target mappings support several types of Uniqueness checks, using the Iteration variable.

The following script is an example of a complex target mapping.

function generateSamAccountName() {
    
	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 sAMAccountName = firstName + '.';
    
	//Check if the middleName variable contains data
    if (typeof middleName !== 'undefined' && middleName) { sAMAccountName = sAMAccountName + middleName.replace(/\s+/g, '.') + '.' }
    
	sAMAccountName = sAMAccountName + lastName;
 
    //Remove leading ...
    sAMAccountName = sAMAccountName.replace(/^\.+/, "");
 
    //Convert to lower case
    sAMAccountName = sAMAccountName.toLowerCase();
 
    //Remove diacritical chars
    sAMAccountName = deleteDiacriticalMarks(sAMAccountName);
     
    //Remove specific chars   
    sAMAccountName = sAMAccountName.replace(/[^0-9a-zA-Z.]/g, '');
 
	//Remove specific chars    
    sAMAccountName = sAMAccountName.replace(/[^0-9a-zA-Z.']/g, '');

	//Shorten string to maxAttributeLength minus iteration length
    sAMAccountName = sAMAccountName.trim().substring(0, maxAttributeLength) + suffix;
 
    //Remove tailing ...
    sAMAccountName = sAMAccountName.replace(/\.+$/, "");

    return sAMAccountName;
}
 
generateSamAccountName();