I am trying to avoid having to populate the dropdo...
# suitescript
p
I am trying to avoid having to populate the dropdown list for every record
b
your description is not good enough to tell what you are doing
it sounds like you are trying to fill in select options for a field
a
I think what he means is that he is trying to populate a field based on a drop down. When the search is empty he gets an error.
p
that is correct
b
wouldnt the solution be not to add it as a select option if its falsy?
p
the field is blank but the script is throwing the error TypeError: Cannot read property "value" from undefined
b
what does your code look like
p
sure. here is the code that looks up the field: allocrule = search.lookupFields({type: search.Type.ITEM,id: itemid, columns: ['custitem_pi_allocationrule'] });
a
instead of
result.value
put
result?.value
. value would then be undefined. You must use suitescript 2.1
result
is whatever undefined variable is giving you an error.
b
your code for getting the lookup is fine
whatever is using it is naively using it without checking if its actually a value
p
how would I check for this? this is the line throwing an error: log.debug({details:"allocrule2 = " + allocrule}); allocvalue = allocrule.custitem_pi_allocationrule[0].value;
is there a way to check if the search returned a value or else do something else if its blank?
b
a
there we go. use
allocvalue = allocrule.custitem_pi_allocationrule[0]?.value;
with the question mark then use
if(!allocvalue)
p
that worked. thank you
is there documentation on the ?
a
👍 1
p
thanks. its too bad they did not add it until 2.1
a
I don't know any other JavaScript... I started in May 2021