1

I have created the lookup search on customer record to get the particular field value.while putting obtained result in alert it showing as [object,object]. and i have converted result to string JSON stringfy method.

The alert showing the result like this :

{"custentity_cseg_customer_categ":[{"value":"6","text":"DTC"}]}

But want the values for the key "text" : Example : DTC in the above code

Code:

Suitescript 2.0 version:
    var customerCategoryFieldLookUp = search.lookupFields({
                    type:'CUSTOMER' ,
                    id: 13,
                    columns: ['custentity_cseg_customer_categ']
                    });

                 alert("CustomerCategoryFieldLookUp:"+ JSON.stringify(customerCategoryFieldLookUp));
Clyde Lobo
  • 9,126
  • 7
  • 34
  • 61
Deepan Murugan
  • 721
  • 2
  • 19
  • 41

3 Answers3

1

This should do the trick for you:

alert( "CustomerCategoryFieldLookUp:"+ custentity_cseg_customer_categ[0].text);

Also the chrome devtools is your friend: press ctrl-shift-j and paste

x = {"custentity_cseg_customer_categ":[{"value":"6","text":"DTC"}]}

into the console now you can look at it and try exploring

James Wakefield
  • 526
  • 3
  • 11
1

This is the expected behaviour of search.lookupFields. Check out the NS Help page titled search.lookupFields(options) for the documented API. Here is what Help says about the return value:

Returns: Object

  • Returns select fields as an object with value and text properties.
  • Returns multiselect fields as an object with value:text pairs.

For example, this method returns results in the following form: { internalid: 1234, firstname: 'Joe', my_select: [{ value: 1, text: 'US Sub' }], my_multiselect: [{ value: 1, text: 'US Sub' },{ value: 2, text: 'EU Sub' }] }

In order to retrieve the value of a select or multiselect field, you need to use Array access:

var customerCategoryFieldLookUp = search.lookupFields({
  type:'CUSTOMER' ,
  id: 13,
  columns: ['custentity_cseg_customer_categ']
});

alert("custentity_cseg_customer_categ:"+ customerCategoryFieldLookUp.custentity_cseg_customer_categ[0].value);
erictgrubaugh
  • 8,519
  • 1
  • 20
  • 28
0

Try console.log(customerCategoryFieldLookUp) to check you object keys. From what I see the object looks like

customerCategoryFieldLookUp {
   custentity_cseg_customer_categ :{
      value:6,
      text:"DTC"
   } 
}

Use
alert(customerCategoryFieldLookUp.custentity_cseg_customer_categ.text)
or
alert(customerCategoryFieldLookUp.custentity_cseg_customer_categ.value)
Rishabh
  • 1,205
  • 1
  • 11
  • 20