Schwifty
04/04/2024, 7:04 PMTypeError: Cannot read property "0" from undefined
When results is {}
I tried checking it against below val == "" || val == null || val == undefined || val.length === 0
But it still goes through the if conditionClay Roper
04/04/2024, 7:07 PMAnthony OConnor
04/04/2024, 7:18 PMAnthony OConnor
04/04/2024, 7:21 PMAnthony OConnor
04/04/2024, 7:22 PMAnthony OConnor
04/04/2024, 7:22 PMSchwifty
04/04/2024, 7:27 PMvar itemTypeVal = search.lookupFields({
type: 'item',
id: itemLine,
columns: ['type']
})
log.debug('itemLog', itemTypeVal);
if (IsNotEmpty(itemTypeVal)) {
var itemType = itemTypeVal.type[0].value
log.debug('itemType', itemType);
}
if (itemType == 'InvPart') {
// update some fields
}
On good results it’s working
{
"type": [
{
"value": "InvtPart",
"text": "Inventory Item"
}
]
}
On bat results, i’m getting just {}
So my if (IsNotEmpty(itemTypeVal))
is still being executedClay Roper
04/04/2024, 7:32 PMClay Roper
04/04/2024, 7:34 PMAnthony OConnor
04/04/2024, 7:41 PMtype
... so just check for a type
key?
if (itemTypeVal.type)
{}
will not pass that conditionClay Roper
04/04/2024, 7:43 PMif ("type" in itemTypeVal)
. I personally prefer the second when looking for a key in case a property exists on an object but is falsey.Schwifty
04/04/2024, 7:45 PMitemTypeVal.type[0].value
as condition
thanks a lot!!
what’s weird is that why other items are throwing blank object even if they have values on their record. the ones having the blank are the non-inventory ones, discount etcClay Roper
04/04/2024, 7:49 PMClay Roper
04/04/2024, 7:49 PMSchwifty
04/04/2024, 7:52 PMClay Roper
04/04/2024, 7:54 PMSchwifty
04/04/2024, 7:57 PMAnthony OConnor
04/04/2024, 8:08 PMNElliott
04/05/2024, 7:06 AMitemTypeVal.hasOwnProperty('type')
Is another option. (until people shoot me down and say why that's a bad idea... 🤭)NickSuite
04/05/2024, 5:16 PMAnthony OConnor
04/05/2024, 5:17 PM