This updates the invoice on edit, but for some rea...
# suitescript
n
This updates the invoice on edit, but for some reason did not update the invoice on create. Not sure why:
Copy code
//BILL TO ADDRESS CHECKBOXES
                switch(scriptContext.type)
                {
                    case 'create':
                    case 'edit':
                        var cust = scriptContext.newRecord.getValue({'fieldId':'entity'});
                        var invCust = record.load({'type': 'customer', 'id': cust, 'isDynamic': false});

                        var addrSublist = 'addressbook';
                        var linecount = invCust.getLineCount({'sublistId':addrSublist});
                        var invDelivery = false;
                        var coverLetter = false;
                        var invEmail = '';

                        for(var line = 0; line < linecount; line++)
                        {
                            var defaultBilling = invCust.getSublistValue({'sublistId': addrSublist, 'fieldId':'defaultbilling', 'line': line});
                            if (defaultBilling == true) {

                                var addressSubrecord = invCust.getSublistSubrecord({
                                    sublistId: addrSublist,
                                    fieldId: 'addressbookaddress',
                                    line: line
                                    });
                                
                                    // Set all required values here.
                                    invDelivery = addressSubrecord.getValue({fieldId: 'custrecord_kes_cfaexcelinvoicedelivery'});
                                    coverLetter = addressSubrecord.getValue({fieldId: 'custrecord_kes_coverletterreqd'});
                                    invEmail = addressSubrecord.getValue({fieldId: 'custrecord_kes_invoiceemail'});
                            }
                        }

                        record.submitFields({
                            'type': 'invoice',
                            'id': scriptContext.newRecord.id,
                            'values':{
                                'custbody_kes_cfaexcelinvdelivery': invDelivery,
                                'custbody_kes_coverletterreqd' : coverLetter,
                                'custbody_kesart_emailcontact' : invEmail
                            },
                            'options':{
                                'ignoreMandatoryFields': true
                            }
                        });

                    break;
                }
a
why don't you add logs and see if it's not executing at all, or if it is, where it stops (or if it gets through the whole script but the change isn't taking effect). you should also log the values you're trying to set, it's possible they're not correct or empty or something.
p
is this a
beforeSubmit
or
afterSubmit
?
scriptContext.newRecord.id
will not work in a
beforeSumit
, is why I ask
🙌 1
s
to add to PNJs comment - a record id does not exist until after it is saved.
n
@PNJ @stalbert it is in aftersubmit
p
The other fun thing could be if you're copying to do your testing and not dealing with
UserEventType.COPY
Anyhow, weekend time! 🙂
party furby 1
s
@Nick although it's not commonly used, i'd also check the UE deployment, there is a body field which can limit the execution to the UserEventType