Translate Non English characters to English characters

Narasimha10
Tera Contributor

Hello All,

I am having a requirement where characters like Ö are coming from third party application to User Table in ServiceNow

As these are non English characters we could not trigger the Integration from ServiceNow.

Can someone help me on this how to translate these characters to English before data being loaded into ServiceNow.

1 ACCEPTED SOLUTION

Karwan Ali
Tera Expert

Hello,

 

Depending on how you are importing the data to the User table (maybe through a data source?) you could transform the data in the transform map record. We are importing through LDAP in my organization and we are transforming the data directly in the transform map. You could do it through script for the specific field that you need to transform.

 

This is an example script that you can use in the transform map script field:

(function transformRow(source, target, map, log, isUpdate) {
    // Define translation map
    var translationMap = {
        'Å': 'A',
        'Ä': 'A',
        'Ö': 'O',
        'å': 'a',
        'ä': 'a',
        'ö': 'o'
        // Add more mappings here as needed
    };

    // Apply transformation to the specified source field and assign the transformed value to the target field
    var transformedFieldValue = transformNonEnglish(source.FIELD_NAME, translationMap);
    target.FIELD_NAME = transformedFieldValue;

    function transformNonEnglish(sourceFieldValue, translationMap) {
        var transformedFieldValue = '';
        // Iterate through each character in the source field value
        for (var i = 0; i < sourceFieldValue.length; i++) {
            var char = sourceFieldValue.charAt(i);
            // Check if the character needs to be translated
            if (char in translationMap) {
                transformedFieldValue += translationMap[char];
            } else {
                transformedFieldValue += char;
            }
        }
        return transformedFieldValue;
    }
})(source, target, map, log, action==="update");

 

Remember to make changes to the translationMap variable to fit your organization's needs.

 

Please mark this as helpful if this helps you out 🙂

View solution in original post

3 REPLIES 3

Karwan Ali
Tera Expert

Hello,

 

Depending on how you are importing the data to the User table (maybe through a data source?) you could transform the data in the transform map record. We are importing through LDAP in my organization and we are transforming the data directly in the transform map. You could do it through script for the specific field that you need to transform.

 

This is an example script that you can use in the transform map script field:

(function transformRow(source, target, map, log, isUpdate) {
    // Define translation map
    var translationMap = {
        'Å': 'A',
        'Ä': 'A',
        'Ö': 'O',
        'å': 'a',
        'ä': 'a',
        'ö': 'o'
        // Add more mappings here as needed
    };

    // Apply transformation to the specified source field and assign the transformed value to the target field
    var transformedFieldValue = transformNonEnglish(source.FIELD_NAME, translationMap);
    target.FIELD_NAME = transformedFieldValue;

    function transformNonEnglish(sourceFieldValue, translationMap) {
        var transformedFieldValue = '';
        // Iterate through each character in the source field value
        for (var i = 0; i < sourceFieldValue.length; i++) {
            var char = sourceFieldValue.charAt(i);
            // Check if the character needs to be translated
            if (char in translationMap) {
                transformedFieldValue += translationMap[char];
            } else {
                transformedFieldValue += char;
            }
        }
        return transformedFieldValue;
    }
})(source, target, map, log, action==="update");

 

Remember to make changes to the translationMap variable to fit your organization's needs.

 

Please mark this as helpful if this helps you out 🙂

Narasimha10
Tera Contributor

Hi Ali,

Thank You for the response.

The logic which you given works for one field right, but we have mapping for around 50 fields from transform map to user table. If any non-English character is filled in any of these 50 fields then it has to be changed to English Character before moving to the target table(User Table).

Can you please help me with this.

Narasimha10
Tera Contributor

Accepted this as a solution as it is working for at least one field