After loading an existing Sales Order, are we able...
# suitescript
a
After loading an existing Sales Order, are we able to grab the shipping address body field values without loading the address sublist? I am encountering undefined variables, and not sure why,
Copy code
if (salesOrderInternalId) {
                            let oldSalesOrder = record.load({
                                type: record.Type.SALES_ORDER,
                                id: salesOrderInternalId,
                                isDynamic: false
                            });

                             const addressFields = [
                                'shipaddressee', 'shipattention',
                                'shipaddr1', 'shipaddr2', 'shipcity',
                                'shipstate', 'shipzip', 'shipcountry'
                            ];

                            addressFields.forEach(field => {
                                let value = oldSalesOrder.getText(field) ? oldSalesOrder.getText(field) : oldSalesOrder.getValue(field);
                                log.debug({ title: 'value', details: field + ', ' + value });
                            });
                            
                        }
c
As you said, you have to load the subrecord.
Copy code
var invoice = record.load({
                type: record.Type.INVOICE,
                id: context.newRecord.id,
                isDynamic: true
            })
            var shippAddrSubRecord = invoice.getSubrecord('shippingaddress')
            var shipAddr1 = shippAddrSubRecord.getText({ fieldId: 'addr1' })
            var shipAddr2 = shippAddrSubRecord.getText({ fieldId: 'addr2' })
            var shipAddr3 = shippAddrSubRecord.getText({ fieldId: 'addr3' })
            var shipCity = shippAddrSubRecord.getText({ fieldId: 'city' })
            var shipState = shippAddrSubRecord.getText({ fieldId: 'state' })
            var shipZip = shippAddrSubRecord.getText({ fieldId: 'zip' })
a
@Corey Schwoebel Thank you for confirming, sir!
👍 1
n
If you use the records browser you will see eth fields you tried to access do not exist. https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2023_1/script/record/salesorder.html "shippingaddress" is the subrecord field you are interested in.
a
@NElliott oddly enough shipcity, shipstate, shipzip do grab the values. The remainer do not. My issue is now trying to set these values on a new sales order in a beforeSubmit. Can you only submit an address on a new order in afterSubmit?