Remember when performing field look-up on a select type of field was as straightforward as this?

var recSO = nlapiLookupField("salesorder", soId, ['status'], false);
var soStatusValue = recSO.status;
var recSO = nlapiLookupField("salesorder", soId, ['status'], true);
var soStatusText= recSO.status;

You call the nlapiLookupField API and you can retrieve the values directly, just like this:

var soStatusValue = recSO.status;
var soStatusText= recSO.status;

You would notice that the API allows you to do this by setting the last parameter to either true or false. Depending on the parameter, you would either get the value or the text:


This is not ideal when you would want to get the text value of the List/Record field and want a combination of different field types.

In SuiteScript 2.0, value returned by the corresponding API will be in a JSON object with ‘value’ and ‘text’ as keys. This way, it is much easier to combine different field types in one lookup call.

Since the value is a JSON object, you need to retrieve the value by its index [0] and its key.  You can refer to the following snippet:

var soStatusValue = recSO.status[0].value;
var soStatusText = recSO.status[0].text;

Looking at the full code in debug mode:

require(['N/search'], function(search) {
var soId = 826;
var recSO = search.lookupFields({
type : "salesorder",
id : soId,
columns : ['status']
var soStatusValue = recSO.status[0].value;
var soStatusText = recSO.status[0].text;

Result would be this:


Hope this helps. Feel free to leave any feedback on the Comments section below. Thanks!

1 comment

Leave a Reply