Scenario:
User is encountering UNEXPECTED ERROR when using the log.debug function of the N/log Module to log URL with stringified array parameters such as:
/app/site/hosting/scriptlet.nl?script=<scriptid>&deploy=<deployid>&compid=<companyid>&ordersArray=%5B123152%2C1521512%5D
Solution:
To prevent encountering the error, User should utilize the JavaScript native method encodeURI() to escape reserved characters in the URL string.
Include the encodeURI() method before displaying the URL string in the details of a log.debug method. See sample client script below:
/**
* @NAPIVersion 2.x
* @NScriptType ClientScript
*/
define(['N/url'],function(url){
function pageInit(scriptContext) {
var ordersarr = [123152, 1521512];
var restletURL = url.resolveScript({
scriptId: <ScriptID>, //input here the Script ID
deploymentId: <deploymentID>,//input here the Script Deployment ID
params: {
ordersArray: JSON.stringify(ordersarr)
},
returnExternalUrl: false
});
log.debug({
title: 'restletURL',
details: encodeURI(restletURL)
});
}
return {
pageInit : pageInit,
};
})