is there a way, in STATIC mode (not dynamic) on cr...
# suitescript
e
is there a way, in STATIC mode (not dynamic) on create of a Sales Order, to add a custom ship to / bill to address? I seem to be able to only reference addresses via the customer (existing addresses) in the SO’s billadresslist and shipaddresslist fields - not able to get the subrecord and save…
Copy code
function addShippingAddress(soRec, payload) {
log.debug('shipaddradd');
        soRec.setValue({
            fieldId : 'shipaddresslist',
            value : null
        });

        soRec.removeSubrecord('shippingaddress');
        log.debug('shipaddradd', 'removed subrecord');
        // Create the subrecord.
        var subrec = soRec.getSubrecord({
            fieldId : 'shippingaddress'
        });
        log.debug('shipaddradd got subrecord', subrec);

        // Set values on the subrecord.
        subrec.setValue({
            fieldId : 'country',
            value : payload.shipcountry
        });

        subrec.setValue({
            fieldId : 'city',
            value : payload.shipcity
        });

        subrec.setValue({
            fieldId : 'zip',
            value : payload.shipzip
        });

        subrec.setValue({
            fieldId : 'state',
            value : payload.shipstate
        });

        subrec.setValue({
            fieldId : 'attention',
            value : payload.shipattention
        });

        subrec.setValue({
            fieldId : 'addressee',
            value : payload.shipaddressee ? payload.shipaddressee : payload.shipattention
        });

        subrec.setValue({
            fieldId : 'addr1',
            value : payload.shipaddr1
        });

        subrec.setValue({
            fieldId : 'addr2',
            value : payload.shipaddr2
        });

        subrec.setValue({
            fieldId : 'addr3',
            value : payload.shipaddr3
        });

        subrec.setValue({
            fieldId : 'addrphone',
            value : payload.shipphone
        });
        log.debug('shipaddradd new subrecord', subrec);
b
looks mostly reasonable, is your problem that the
shipaddress
field has the wrong value, or are the actual fields of the subrecord not set
e
thanks for the quick response, @battk… subrecord seems set ok (based on logging). the error is on save of the order (outside of that block, but just a
rec.save()
) where the error reads “Ship To, Bill To not set” or the likes
always confused by these… there’s shipaddresslist and shipaddress -
DYNAMIC mode works fine, too. But I cannot be in dynamic mode for other reasons
do you know - do i need to set the shipaddresslist to -Custom- somehow as well?
b
my guess is that another customization is throwing the error, in which case you need to find out when it throws the error
e
hmm. interesting. but not in dynamic mode?
b
the guess here is that the customization is checking a calculated field like
shipaddress
e
ok, i’ll try undeploying a number of scripts against the SO and see what happens
they are mandatory on the form though
b
which field
e
those two fields were mandatory in the form (Bill To, Ship To) but I removed that and the error still exists. I’ll try via Script Records. There are also Workflows deployed, perhaps one of those.
ok, so it was the required/mandatory fields in the end as I just tried again and it worked - but the Ship To is EMPTY. When you get the subrecord, is there any “commit” that has to occur to save it? I’m just confused why the
shipaddress
field does not save the data added to the subrecord.
b
shipaddress
has an annoying tendency to not get set from the subrecord
though its more common in user event scripts
e
this is a restlet
b
you may want to try removing
Copy code
soRec.setValue({
            fieldId : 'shipaddresslist',
            value : null
        });

        soRec.removeSubrecord('shippingaddress');
which are the unusual things in your logic
e
ok ok will try
wow, seems to have worked! oh man i don’t know why that was there exactly, need to go back to check - but thank you! resolved
s
I find I rarely have to touch
shipaddresslist
to do what I need with address subrecords.
e
thanks