Monday, June 3, 2019

Handling Commas in URL Using SuiteScript

In NetSuite, users can pass URLs as parameters on Application Navigation APIs like nlapiRequestURL and nlapiSetRedirectURL. The problem is that some special characters are not handled properly, like comma(,). Commas are stripped out, and this in effect makes the URL incorrect.

In order to effectively handle URLs with comma,  encode the URL first before sending it over to the Application Navigation API:

var URL = "http://www.yoursite.com/category/keyword1,keyword2";
var encodedURL = encodeURIComponent(URL);
var response = nlapiRequestURL(encodedURL);

The encodeURIComponent converts the comma symbol into its equivalent URL-encoded value. For comma, its equivalent value/symbol is %2C

No comments:

Post a Comment