Netsuite | How to Use JSON.stringify(s) in server-side SuiteScript

JSON (JavaScript Object Notation) is available for client-side Suitescript, another popular usage JSON is the ‘stringify’ method it is primarily used in converting JavaScript data structures into JSON text.

In Netsuite suitescript JSON.stringify(s) is available in client-side script. However in server-side suitescript you will get an error when calling this method.

Stringify(s) is an open source code and it can be located at :

http://www.json.org/json2.js

Copy the javascript source code and save it as a file and include it as a class library in your server-side script’s deployment.

Here is a sample usage in user event suitescript:

function onBeforeLoad(type, form, request)
{
	if(type == "edit")
	{
		var transaction = new Object();
		transaction.countryCode = "PH";
		transaction.shipItem = "PS3";
		var test = JSON.stringify(transaction);
		nlapiLogExecution('DEBUG', 'json: ', test);
	}
}

As a result, you would have a JSON format values in this format:

"{"countryCode":"PH","shipItem":"PS3"}"

Related posts:

  1. Netsuite | How to know if a form has a client-side suitescript
  2. Tutorial – How to DEBUG Suitescript using Google Chrome

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>