0
votes

We use custom segments to track sales channel on sales orders. The Sales Channel custom segment record has three fields: Internal ID, Name, Raw_Channel. Example values are:

1, Amazon.com, AMAZON_COM
2, Amazon.ca, AMAZON_CA
3, Amazon.uk, AMAZON_UK

Raw_Channel is a text field on Sales Orders that is populated when an order is imported to NetSuite by our marketplace connector (the connector pulls orders from the various Amazon marketplaces and imports them into NetSuite).

What I'm hoping to do is to use the Raw_Channel field to look up the Sales Channel ID and set the value of the Sales Channel drop-down custom segment field using an After Record Submit script. Below is a start but it obviously won't work since nlapiLookUpField uses Internal ID to look-up values but I only have Raw_Channel as a reference which is not the ID.

My ultimate question is, how do I get the Sales Channel Internal ID by using a non-ID field as a look-up field? Help is very much appreciated!

function setChannel (){
    var rawchannel = nlapiGetFieldValue('custbody_raw_channel')
    var channelid = nlapiLookUpField('cseg_tt_channel', rawchannel, 'id')
    nlapiSetFieldValue('custbody_cseg_tt_channel', channelid)
}
1

1 Answers

1
votes

nlapiLookUpField is only useful if you already have the Internal Id of the record.

You will need to construct a search using nlapiSearchRecord or nlapiCreateSearch with a filter for the raw channel.

You can read more about scripting searches in the Help Center here.

I find this Chrome extension immensely helpful when building searches in SuiteScript. It allows you to create a search in the UI and automatically generate the SuiteScript code.