Sunday, January 13, 2019

Retrieve item options value on Sales Order using SuiteScript

Customer is reading 'options' column field on the item in a sales order using getLineItemValue API
however it appears that it returns the string value with field id , label and value on it.

e.g. CUSTCOL4FFlavor Cookie2Ola OatmealCUSTCOL5FSize 3Small

To be able to get each options you must delimit it using CHR(4) or the ANSI control character with code 4
and to be able to get each item option values you must delimit CHR(3) or the ANSI control character with code 3

Below is a sample code:

Delimit the item options using CHR(4) or the ANSI control character with code 4

var cString = String.fromCharCode(4);
var set_of_option_array = optionString.split(cString);

"set_of_option_array" variable will contain two values

set_of_option_array[0]: CUSTCOL4FFlavor Cookie2Ola Oatmeal

set_of_option_array[1]: CUSTCOL5FSize 3Small

On the next step, you need to split the option values using CHR(3) or the ANSI control character with code 3

var ext_String = String.fromCharCode(3);
var each_option = set_of_option_array[i].split(ext_String);
*each_option is an array of string that contains the values of option

set_of_option_array[0]:
each_option[0] CUSTCOL4
each_option[1] F
each_option[2] Flavor Cookie
each_option[3] 2
each_option[4] Ola Oatmeal


set_of_option_array[1]:
each_option[0] CUSTCOL5
each_option[1] F
each_option[2] Size
each_option[3] 3
each_option[4] Small

 

No comments:

Post a Comment