Using nlapiRequestURL, we can POST special characters by directly converting it to its html equivalent.
Example:
var post_data = new Array();
post_data["email"] = 'ünoemail@noemail.com';
'ü' will return ü.
These HTML codes can normally be found here:"http://www.ascii.cl/htmlcodes.htm".
There is an easier way other than manually encoding the special characters HTML equivalent. We can use these Javascript Global Functions to automate the request.
1. encodeURI - This function encodes special characters, except: , / ? : @ & = + $ # (Use encodeURIComponent() to encode these characters).
Tip: Use the decodeURI() function to decode an encoded URI.
2. escape - The escape() function encodes a string.
This function encodes special characters, with the exception of: * @ - _ + . /
Tip: Use unescape() to decode strings.
3. encodeURIComponent() - The encodeURIComponent() function encodes a URI component.
This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #
Tip: Use the decodeURIComponent() function to decode an encoded URI component.
Sample code snipet:
var str = 'órocan';
str = encodeURI(str);
var postData = new Array();
postData['specialstring'] = str;
var response = nlapiRequestURL('https://forms.netsuite.com/app/site/hosting/scriptlet.nl?script=175&deploy=1&compid=TSTDRVOROCAN&h=8b0846af4561ee31c7de', postData, null, null);
}
Suitelet code accepting the POST request:
var str = request.getParameter('specialstring');
str = decodeURI(str);
nlapiSubmitField('salesorder', '666', 'memo', str);
}
No comments:
Post a Comment