Friday, September 21, 2018

How to set umlaut characters in a free form text field using nlapiSetFieldValue

Question/Problem: 
 
Customer would like to set umlaut characters via script in a free form text field. If the umlaut character is set by script, it is rendered in the UI as a replacement character, as opposed to when it is entered manually in the UI.
 




Answer/Solution:
 

Use the unescape Javascript function and the hexadecimal equivalent of the umlaut character. For example, if we are setting a text with umlaut characters in custbodyx (free form text field):

1.     Sample code:

var stUmlaut = 'Ü and ä';
nlapiSetFieldValue('custbodyx', stUmlaut);

     Result: The custbodyx will render stUmlaut as "� and �". The replacement character which is a question mark inside a black diamond or a square symbol is displayed for the umlaut symbols.

 

      2. To resolve this we need to use the unescape function and the hexadecimal equivalent of the umlaut character.   Sample Code:


var stUmlaut = unescape('%DC') + ' ' + ' and' + ' ' + unescape('%E4');
nlapiSetFieldValue('custbodyx', stUmlaut);

Result:  The custbodyx will read stUmlaut as "Ü and ä".

No comments:

Post a Comment