I'm trying to get value for a multi-select field b...
# suitescript
a
I'm trying to get value for a multi-select field by using getValue() method and this is the result:
Copy code
Ljava.lang.Object;@
what is it? how can I get the value for that field?
b
Hopefully is an array
👍 1
Suitescript 2 is supposed to be better at hiding that its java pretending to be javascript
a
how can I get the values for a multi select field
actually I want to set a new value for that field but I don't want to delete the previous values. so, I need to read the previous value and then add the new value to the array and then set the new array as a value
@battk is that right approach? if yes how can I read the value?
b
reading the value should be just using getValue
a
but the result is Ljava.lang.Object;@
b
what does your code look like
a
I want to get the value and add a new value to the array if it's not in the array and then set the new value to the multi select
if set it just with the new value it will delete(unselect) previous values and set just the new one. so I have to read previous values.
n
@Ali you have a couple of errors in your code, here it is corrected and added what I think you need to do, haven't tested the code though.. but basically you should get an array when doing getValue, you then need to add the ID (in my example represented by the <id> (so change that)) to that array, then set the array with the added value to be the new value of the field:
Copy code
let contactRec = record.load({
                    type: record.Type.CONTACT,
                    id: contactId
                });

                const contactPerfs = contactRec.getValue('custentity_cont_contact_preferences');

                contactPerfs.push("<id>");

                contactRec.setValue({
                    fieldId: 'custentity_cont_contact_preferences',
                    value: contactPerfs
                });

                contactRec.save();
btw the <id> is the list id of the value you wanna set