Friday, September 21, 2018

Add a String Value with Single Quotes and Double Quotes in Suitescript

A string value is needed to be passed/set in SuiteScript and it contains single quotes/double quotes. In programming, string values are usually enclosed in single/double quotes and single/double quotes within the value will cause syntax errors.

  1. For a string value with double quotes in the string, enclose the string value with double quotes in a single quotes, i.e:
  2. nlapiSubmitField('salesorder', '820', 'custbody11', '"Test Value"', true);
  3. For single quotes within the string, use a 'backslash' character to escape the single quote, i.e:
  4. nlapiSubmitField('salesorder', '820', 'custbody11', '\'Test Value\'', true);
  5. An example of combination of single and double quotes, i.e:
  6. nlapiSubmitField('salesorder', '820', 'custbody11', '\'Test Value\', "I am a continuation of the string"', true);
  7. An example of using Unicode values for the special characters:
  8. nlapiSubmitField('salesorder', '820', 'custbodysubscriptiontype', '\u0027Test Value\u0027, \u0022I am a continuation of the string\u0022', true);

No comments:

Post a Comment