Retrieve Values for Multi-Select Field Being Return by nlapiLookupField

Written by
Manuelito Macalinao
Published on
November 30, 2023 at 7:41:04 AM PST November 30, 2023 at 7:41:04 AM PSTth, November 30, 2023 at 7:41:04 AM PST

Scenario

Using nlapiLoadRecord then nlobjRecord.getFieldTexts function to retrieve multi-select field selected values will return an array. However this is not the case when you try to retrieve values using nlapiLookupField as it will return String values.

Solution

In order to convert this to array, we can use a JavaScript function such assplit(), to split string to an array ofsubstrings.The sample code below is a resolution for this concern:

var multi_select =nlapiLookupField('inventoryitem', id,'custitem_multi_select',true);// "custitem_multi_select" is a custom multi-select field created on the inventory record.var split_multiselect = multi_select.split(",");// use split function to return an array of substrings and parameter would be comma (",") as the values is separated with comma.//Then you loop through the array to get the valuesfor(var x=0; x < split_multiselect.length; x++){nlapiLogExecution('DEBUG','DEBUG',split_multiselect[x]);}