Is it possible to dynamically source data and set ...
# suitescript
m
Is it possible to dynamically source data and set a list field? I need to source customer addresses onto a custom list field (type address), ideally on beforeload. I am able to get the addresses and set it to a freetext, but need it for a dropdown list for selection.
b
the non suitescript answer is to create a addressbook list field that uses filtering to limit the options to match an entity field
in an annoynace of netsuite, it has to be an entity field, a customer field wont work
the suitescript answer is to make your own field in the beforeLoad and add your own select options
m
create a list field in code or ui? what can we use to create it in code?
b
the suitescript answer uses Form.addField and either Field.addSelectOption or Field.insertSelectOption to add select options
m
thank you. will take a look now. also, just had a quick look at the addressbook/filter and I was able to retrieve the addresses but only for a specified entity
is there an option to compare with whatever the customer record is on the case?
b
you have to create an entity field on the case to use for the filtering
m
I got it to filter using an additional field referencing entity. I should be able to auto set that field using a WF on record load.
I wasn't able to use the WF as I hoped. So reverted to using Script. I am able to create the list field and populate it. But the display looks odd, as I am setting the value from addressbookaddress_text - all the lines are one string value. I think it would be better to get the specific field values and concatenate them but can't seem to get into an address.
Copy code
const address_count = CUSTOMER.getLineCount('addressbook');
log.debug({title: "Address Count", details: address_count});

if (address_count > 0) {
    for (var x = 0; x < address_count; x++) {

        var address_subrecord = CUSTOMER.getSublistSubrecord({
            sublistId: 'addressbook',
            fieldId: 'address',
            line: x
        });

        var add1 = address_subrecord.getValue({ fieldId: "addr1" });
        var add2 = address_subrecord.getText({ fieldId: "addr2" });

        log.debug({ title: "Add1:", details: add1 });
        log.debug({ title: "Add2:", details: add2 });

        var concat_address = add1 + " " + add2;

        address_list.addSelectOption({
            value: concat_address,
            text: concat_address,
            isSelected: false
        });
Error: Field address is not a subrecord field.
b
summary types are subrecords
as an alternative, you can load the customer record and inspect its sublist in code
subrecord fields usually have other fields that are related to them
usually at least {subrecordFieldInternalId}_key
m
thanks. I managed to get the address out. it was more simpler than I thought. address_subrecord = CUSTOMER.getSublistSubrecord & address_subrecord.getValue({fieldId: "addr1"}); etc