Anyone face issue with "lookupFields", Some time i...
# suitescript
l
Anyone face issue with "lookupFields", Some time it won't works like, its says undefined?
n
You would have to share your code to know for sure but depending on the type of field you're looking up, you access the value slightly differently. Just about every time I use that function I test what the return will look like in the debugger before committing code. I'd be inclined to try your code in debugger, you may be referencing the return value(s) incorrectly.
l
Copy code
var roleobj = search.lookupFields({
						type: 'customer',
						id: customerid,
						columns: ['custentity_cust_type','custentity_primary_cust_type']
					});
this is the code, But sometime roleobj simply returns undefined, but sometime it works
I would 1/2000
any reason why?, I can load the record that not an issue, but I just wanted to confirm that Yes lookupFields API has an issue with it.
@NElliott??
n
hold on mate I'm in a meeting.
k
@Lucas are those fields Select Fields or MultiSelect fields?
l
"custentity_cust_type" is multi select and "custentity_primary_cust_type" is single select @karlenigma
But Just FYI, I never faced that issue again, we received this issue only at once, in entire 6 months
p
Probably just a blip. Network problem, server brainfart, or something
l
Ohkk
k
The only reason i mention select fields etc is sometimes you have to refernce an array to get the value
👍 1
l
So, Do you thing I need to use load record API, if Lookup does't works?, Means just a check after lookupfield?
k
no.
You can do roleObj.custentity_cust_type[0]
I would log the roleObj and see what comes back
Then you can reference your field after seeing what come back.
l
I have used some thing like this
Copy code
if(roleobj.custentity_primary_cust_type && roleobj.custentity_primary_cust_type[0]!=undefined){...}
k
do a log.debug({title: ‘roleObj’, details: roleObj}); and let me know what is returned.
l
Ok
Here it is @karlenigma
Copy code
{
  "custentity_cust_type": [
    {
      "value": "14",
      "text": "ONC_WC"
    }
  ],
  "custentity_primary_cust_type": [
    {
      "value": "14",
      "text": "ONC_WC"
    }
  ]
}
k
So yeah To get your value for custentity_cust_type then roleObj.custentity_cust_type[0].value or text if you want the text
l
Sorry, I didn't get that
Actually, I received error for roleobj error says roleobj is undefined @karlenigma
and at only once.. in entire 6 months
k
ah right.
p
If yo had 1 random failure in 6 months I don’t think yo really need to worry
e
You need to evaluate each property separately.
b
although i have nothing to say for your weirdness
Copy code
if(roleobj.custentity_primary_cust_type && roleobj.custentity_primary_cust_type[0]){...}
is generally preferred over
Copy code
if(roleobj.custentity_primary_cust_type !=undefined && roleobj.custentity_primary_cust_type[0]!=undefined){...}
if you really only wanted to compare against undefined, you use !== undefined