I am writing a beforeLoad handler in a user event ...
# suitescript
c
I am writing a beforeLoad handler in a user event script for an item fulfillment record. I want to get the value of a custom field on the shipping address record. I need it to work for fulfillments of sales orders and transfer orders. When the item fulfillment is for a sales order, the object returned by context.newRecord.getSubrecord('shippingaddress') does contain custom fields. However, when the item fulfillment is for a transfer order, the object returned by context.newRecord.getSubrecord('shippingaddress') does NOT contain custom fields. So I want to try to load the address record using its internal id, and see if the result includes custom fields. Ideally I'd like to use record.load, but record.Type.ADDRESS doesn't seem to exist, according to https://docs.oracle.com/cloud/latest/netsuitecs_gs/NSAPI/NSAPI.pdf. So I thought about doing a search for addresses by internal id, but the search results would not include custom fields, according to https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2019_2/script/record/address.html. And anyway, I can't see how to get the internal id of the shipping address from the item fulfillment. Of all the fields listed at https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2019_2/script/record/itemfulfillment.html, none seem to provide the internal id of the shipping address. I've tried getting it from the result of context.newRecord.getSubrecord('shippingaddress') but with no success. So I'm stuck. Any ideas? I've posted this question at https://stackoverflow.com/questions/60530341/how-to-get-custom-field-of-shipping-address-of-item-fulfillment-when-fulfilling and https://netsuiteprofessionals.com/question/how-to-get-custom-field-of-shipping-address-of-item-fulfillment-when-fulfilling-transfer-order/
j
There isn't an ENUM value for 'address' but you can pass it into a script search as its string value. From there you can look up your custom fields. This only solves half your problem as you still need to get the address internal id.
Copy code
var addressColumns = [
                'attention',
                'address1',
                'city',
                'countrycode',
                'state',
                'zip'
            ];
            var address = {};
            search.create({
                'type': 'address',
                'columns': addressColumns,
                'filters': [['internalid', 'anyof', id]]
            }).run().each(function (result) {
                address = {
                    'ref': id,
                    'attention': result.getValue('attention'),
                    'address1': result.getValue('address1'),
                    'city': result.getValue('city'),
                    'country': result.getValue('countrycode'),
                    'state': result.getValue('state'),
                    'zip': result.getValue('zip')
                };
            });
c
Thanks for this. How can I get a custom field value though? I can't see any documented way to access them. That's what I meant when I wrote: "So I thought about doing a search for addresses by internal id, but the search results would not include custom fields, according to https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2019_2/script/record/address.html."
s
Of course, the record browser is a shared document, so it won't contain any information specific to your account, like custom fields. However, you can usually access them just like any other field, referencing them by script id in the columns array.
c
@scottvonduhn In my experience of doing searches in SuiteTalk, custom result fields are in a dedicated list, not part of the list of standard fields. Is that not the case with SuiteScript? Regardless, I can't see how to get the internal id of the shipping address anyway, so I don't know how I'd search. (See towards the end of my original post.)
s
You are correct, unlike with SuiteTalk, in SuiteScript standard and custom fields are not treated any differently. You can use them in saved search columns, formulas, filters, and joins just like standard fields.
c
@jarens This returned a blank value