JS customization of additional attributes

Formatting additional attributes with JS

To allow customized formatting of additional attributes, the following function will be called for every additional attribute that is available on a page:

iam.api.additionalAttributes.format(attributeName, attributeValue) => any

This function provides the additional attribute name and value. The value can be modified by the function and returned.

For additional attributes of type object, the entire object is passed to the function and can be processed and returned.

// Example phoneNumber
iam.api.additionalAttributes.format = (attributeName, attributeValue) => {
    if (attributeName === 'phoneNumber') {
        return formatPhoneNumber(attributeValue); // formatPhoneNumber is a custom function implemented by the customer
    }
    return attributeValue;
}

// Example with objects
iam.api.additionalAttributes.format = (attributeName, attributeValue) => {
    if (attributeName === 'consent') {
        attributValue.clientName = attributeValue.clientName.toUpperCase(); // "clientName" property from "consent" object has been modified
        return attributValue;
    }
    return attributeValue;
}

To provide translated values in JS, use the following function to determine the current language:

iam.api.language.current() // returns the current language, e.g. 'en' - available locales are defined by the language setting in the Loginapp

The function call happens before translations are applied so that the modified values are used in the translations.