3

Below is my search code. I'm searching for the Invoice number by using the invoice internal ID.

What is the right way to access the lookupFields search result?

var invoiceNumber = fieldLookUp.value;

I'm using the above line but the "invoiceNumber" is empty. Thanks for your help.

var fieldLookUp = search.lookupFields({
                    type: search.Type.INVOICE,
                    id: invoiceId,
                    columns: 'tranid'
                });

                var invoiceNumber = fieldLookUp.value;
mana
  • 1,075
  • 1
  • 24
  • 43

2 Answers2

4

It would just be fieldLookUp.tranid. lookupFields returns an Object where the Object's keys are your Columns and the Object's values are the Column values.

Check out this video for more details on Field Lookups in SS2.0: https://www.youtube.com/watch?v=_fs2thUdEmQ

erictgrubaugh
  • 8,519
  • 1
  • 20
  • 28
  • For me this returns org.mozilla.javascript.NativeArray@3ae2d1c2 – cja Mar 10 '20 at 10:28
  • 1
    That's correct. A Lookup on any type of Select field returns an Array. Stringify the return value in your logs so you can see its structure correctly. – erictgrubaugh Mar 10 '20 at 14:20
0

If you want to get only the value

fieldLookUp[0].value

or vice versa, if you want to get the text data

fieldLookUp[0].text
tyne
  • 97
  • 5