Script to replace Accented characters and remove Special Characters from a field

In order to do so, the script concerning the Field needs to be changed and should contain the following:

1. Get the value of the desired field through objRecord.getValue()

2. Replace all characters with accents to their corresponding letters

3. Remove all special characters

4. Set the new value of the desired field through objRecord.setValue()

5. Kindly check the values by navigating through Customization > Scripting > Script Deployments  > Find your Script > View > Execution Log

Note: The deployment setup on n LOG LEVEL should be set to DEBUG.Below is a sample SuiteScript 2.0 Code Snippet using the ‘N/record’ module:

//Step 1
var iVal = objRecord.getValue({
    fieldId: 'xxxxx'
});
log.debug('DEBUG', iVal);

//Step 2 and 3
var accents = 'ÀÁÂÃÄÅàáâãäå�'�
"�"
ÕÕÖ� òóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûü� 'ñŠšŸÿýŽž';
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
iVal = iVal.split('');
var strLen = iVal.length;
var i, x;
for (i = 0; i < strLen; i++) {
    if ((x = accents.indexOf(iVal[i])) != -1) {
        iVal[i] = accentsOut[x];
    }
}
var newVal = iVal.join('');
log.debug('DEBUG', newVal);
var fVal = newVal.replace(/[^A-Z0-9]/ig, "");
log.debug('DEBUG', fVal);

//Step 4
objRecord.setValue({
    fieldId: 'xxxxx',
    value: fVal,
    ignoreFieldChange: true
});
 Reference SuiteAnswer Id: 80229

Leave a comment

Your email address will not be published. Required fields are marked *