The subrecord for the 'ship to' field on a line it...
# suitescript
t
The subrecord for the 'ship to' field on a line item - is the ID shipaddress or shippingaddress?
e
Records Browser says
shipaddress
, but the method will throw an error if its wrong
t
Yeah, that's what I saw too. When I try to use shipaddress, it throws an error. When I use shippingaddress, no error gets thrown but no subrecord gets created on the item so I'm trying to figure out where the issue is
I can use setValue() on a subrecord, correct? Some of the docs made it seem like I had to use setCurrentSublistValue()
e
Do subrecords even contain a
setCurrentSublistValue()
method?
t
Apparently, according to NetSuite
e
that would only be if you are working with sublist items on the subrecord itself, which an address doesn't have any sublists
subrecords have exactly the same API as a Record, so you work with them the same way
so if you're trying to set a body field value on a subrecord, then you call
setValue()
on that subrecord
just like you would with a normal record
t
Ok, so far I have all that correct. I set the values on the subrecord, then when I log.debug the subrecord, I see all the correct values in there. However, even after calling record.commitLine(), the subrecord still doesn't show on the new sales order 😞
e
Believe I had a coaching student who ran into something similar and ended up having to do all her subrecord work in 1.0
t
Yikes, let's hope that doesn't happen haha
Not that it really matters, but I have an update on this. I switched from trying to reload the Sales Order and adding the address subrecord, to doing it as I'm initially creating the line items. For some reason this worked where the other method did not. Nice to know I suppose
m
Hi Tyler, could you post your scripts so we could investigate on our side if there is something wrong when working with address subrecords on item lines?
s
I struggled with figuring out how to set the address subrecord on a sales order. The documentation was totally horrible and I had to do a lot of guess and check but if you still need this I can post what I did
Copy code
function setAddress(salesOrder, type) {
            salesOrder.setValue({
                fieldId: type + 'addresslist',
                value: ''
            });

            var addr;
            if (type === 'bill') {
                addr = salesOrder.getSubrecord({
                    fieldId: 'billingaddress'
                });
            } else {
                addr = salesOrder.getSubrecord({
                    fieldId: 'shippingaddress'
                });
            }

            // Get all values
            var addressee;
            var addr1;
            var addr2;
            var city;
            var state;
            var zip;
            var phone;

            addr.setValue({
                fieldId: 'country',
                value: 'US';
            addr.setValue({ fieldId: 'addressee', value: addressee });
            addr.setValue({ fieldId: 'addr1', value: addr1 });
            addr.setValue({ fieldId: 'addr2', value: addr2 });
            addr.setValue({ fieldId: 'city', value: city });
            addr.setValue({ fieldId: 'state', value: state });
            addr.setValue({ fieldId: 'zip', value: zip });
            addr.setValue({ fieldId: 'addrphone', value: phone });
            salesOrder.setValue({
                fieldId: type + 'address',
                value: addr1 + '\n' + addr2 + '\n' + city + ', ' + state + '\n' + zip + '\n' + phone
            });
        }
t
function setItemSublistFields(SalesOrder) { if (SalesOrder.itemFields) { _.map(SalesOrder.itemFields, function (sublistLine) { SalesOrder.record.selectNewLine({ sublistId: 'item' }); _.map(sublistLine, function (field) { if (field.value && field.id != 'rate') { if (field.id == 'item') { SalesOrder.record.setCurrentSublistText({ sublistId: 'item', fieldId: field.id, text: field.value }) } else { field = validation.lookForInternalId(SalesOrder.record, field) if (field.formattedValue) { SalesOrder.record.setCurrentSublistValue({ sublistId: 'item', fieldId: field.id, value: field.formattedValue }) if(field.id == 'shipmethod') { log.audit('field', SalesOrder.record.getCurrentSublistValue({ sublistId: 'item', fieldId: 'shipmethod' })) } } else { SalesOrder.record.setCurrentSublistValue({ sublistId: 'item', fieldId: field.id, value: field.value }) } } } }) log.audit('subsid', SalesOrder.record.getValue('subsidiary') == 2) if(SalesOrder.record.getValue('subsidiary') == 2 || SalesOrder.record.getValue('subsidiary') == 5) { SalesOrder.record.setCurrentSublistValue({ sublistId: 'item', fieldId: 'rate', value: 1 }) } if (SalesOrder.isDropShip && !SalesOrder.isCanadaOrder) { populateLineItemAddress(SalesOrder, sublistLine); } SalesOrder.record.commitLine({ sublistId: 'item' }) log.audit('committed') }) } }
function populateLineItemAddress(SalesOrder, item) { var addressSubrecord = SalesOrder.record.getCurrentSublistSubrecord({ sublistId: 'item', fieldId: 'shippingaddress' }) _.forIn(item, function (field) { if (field && field.value) { addressSubrecord.setText({ fieldId: field.id, text: field.value }) } }) return addressSubrecord; }
That is the code that ended up working for me 🙂