Has anyone run into an issue where ship to address...
# suitescript
m
Has anyone run into an issue where ship to addresses are often not being set on a sales order on create? Exact same code always sets on update, but a significant percentage simply have the country set instead of the full address set on create. This is via SS2.1 in dynamic mode
No error messages, i am logging the data being set and it's the same data every time, runs with the same code every time (regardless of create or update)
Here's my code-
Copy code
function setAddress(address, addressType) {
      // If SO has invoices already don't try to re-set shipping address
      invoice_line_number = rec.findSublistLineWithValue({
        sublistId: 'links',
        fieldId: 'type',
        value: 'Invoice'
      });
      // if (invoice_line_number !== -1) return;

      // This should prevent the system from overriding the inputted address with a default address (if one exists).
      try {
        var addressListType = addressType === 'shippingaddress' ? 'shipaddresslist' : 'billaddresslist';
        setterMethod(addressListType, -2); //-2 seems to be for setting a custom address
      } catch (e) {
        log.debug('Cannot reset ' + addressListType, e);
      }

      var addressrec = rec.getSubrecord({ fieldId: `${addressType}` });

      addressrec.setValue('country', address['country']);
      addressrec.setValue('zip', address['zipcode']);
      addressrec.setValue('addr1', address['street']);
      addressrec.setValue('addr2', address['street2']);
      addressrec.setValue('city', address['city']);
      addressrec.setValue('state', address['state']);
      addressrec.setValue('addressee', address['organization_name']);
      if (address['person_name']) addressrec.setValue('attention', address['person_name'].slice(0,149));
    }
a
There's nothing in the above code that explicitly works differently for create vs. update, and it works fine in update, therefore this code isn't the issue. entry point for this script?
I'd probably also want to see the
setterMethod
code and have logs in this function for the two parameters on entry
address
and
addressType
m
It's a restlet, settermethod is pretty basic-
Copy code
function setterMethod(field, value) {
      if (typeof (value) !== 'undefined') rec.setValue(field, value);
    }
I am logging the address where i'm calling the function
Copy code
log.audit('shippingaddress', context['shippingaddress'])
      if (context['shippingaddress']) setAddress(context['shippingaddress'], 'shippingaddress');
I went a little crazy and added a logging statement to every setvalue...
Copy code
function setAddress(address, addressType) {
      // If SO has invoices already don't try to re-set shipping address
      invoice_line_number = rec.findSublistLineWithValue({
        sublistId: 'links',
        fieldId: 'type',
        value: 'Invoice'
      });
      // if (invoice_line_number !== -1) return;

      // This should prevent the system from overriding the inputted address with a default address (if one exists).
      try {
        var addressListType = addressType === 'shippingaddress' ? 'shipaddresslist' : 'billaddresslist';
        log.audit('setting addresslisttype', setterMethod(addressListType, -2)) //-2 seems to be for setting a custom address
      } catch (e) {
        log.debug('Cannot reset ' + addressListType, e);
      }

      var addressrec = rec.getSubrecord({ fieldId: `${addressType}` });

      log.audit('setting country', addressrec.setValue('country', address['country']))
      log.audit('setting zip', addressrec.setValue('zip', address['zipcode']))
      log.audit('setting addr1', addressrec.setValue('addr1', address['street']))
      log.audit('setting addr2', addressrec.setValue('addr2', address['street2']))
      log.audit('setting city', addressrec.setValue('city', address['city']))
      log.audit('setting state', addressrec.setValue('state', address['state']))
      log.audit('setting addressee', addressrec.setValue('addressee', address['organization_name']))
      if (address['person_name']) addressrec.setValue('attention', address['person_name'].slice(0,149));

    }
Here's the one from the last one-
Copy code
setting addressee	01/17/2024	10:33 am	Scientist Admin	{"type":"address","isDynamic":true,"fields":{"sessioncountry":"US","country":"DE","freeformstatepref":"F","nlloc":"0","nlsub":"1","recalculate_address_text":"F","city":"Monheim am Rhein","_eml_nkey_":"4838887~1613~1016~N","type":"address","enable_subrecord_to_parent_synchronization":"F","nsapiCT":"1705516396932","sys_id":"-16759536691545054","nluser":"1613","nldept":"8","dropdownstate":"","createdbylegacyfields":"F","override":"F","state":"","zip":"40789","templatestored":"F","sys_parentid":"-16759534308693375","addr2":"Alfred-Nobel-Strasse 50","address_fields_already_synced":"F","addr1":"ATTN: Dr. Fabian Weysser Geb. 6250, Raum 07","addrlanguage":"en_US","nlrole":"1016","baserecordtype":"address","addressformat":"<$attention$>\n<$addressee$>\n<$addr1$>\n<$addr2$>\n<$addr3$>\n<$city$> <$state$> <$zip$>\n<$country$>","onlyaddresstextisvalid":"F","customform":"-10870","addressee":"Bayer AG Research Logistics","addrtext":"Germany"}}
so i do think it's being set...
I set the billing address next and that address has the same logs (and same code just billingaddress) and does persist
a
interesting... okay then my guess would be you're setting something ELSE after address that's causing it to get wiped. Since its in dynamic mode the order in which you set things matter. subsidiary, customer, department, class, location, account would be the most common ones I make sure to set first. I don't recall having an issue with shipping address though
m
Yeah, to me shipping address needs to be set early to define tax nexus but I think there has to be something later i agree. I'm trying now in console so i can check the address subrecord after basically every other value being set. It was turning into a pain to log subrecord values in the script itself
Thanks for the feedback anthony, i'll keep you in the loop
👍 1
FYI in total order i do entity, the subsidiary, then ship to address, then line items, then custom fields
a
i guess the other thing to check would be if you have any WF or UE scripts on beforeSubmit in a create context only that might be making the edits?
m
Doing it in the console worked... only issue i ran into was the nexus wasn't setting properly (which I don't think is an error i hit via the restlet because it caused an actual setting error in console which i don't see in the restlet)
Yeah i'll have to check that too. In the System Information it shows the restlet as the setter of the address value (which is just the Country when not setting properly)
a
hmm the more you say about this the weirder it seems 🙂 curious how this one turns out
m
I guess... not what I need to be working on today and just really hoping I don't end up having to contact netsuite support fingers crossed
a
ugh yeah don't do that, that's admitting defeat, I believe in you!
m
Not to worried about admitting defeat, just not confident in netsuite support's ability to debug and the wasted time filling out their questionnaires. Anyway, added logging to confirm nexus is indeed set correctly...
It's strange, when i try logging rec.getSubrecord('shippingaddress').getValue('addr1') outside of the setAddress method it is returning a blank value. In the setAddress method it's definitely setting values, but I guess this instance of the subrecord isn't saved? so when I call getSubrecord later it's getting the unchanged initial version maybe?
e
I am having this same issue. We discovered it impacted Estimate->Sales order conversion from the MyAccount portal. I filed and issue with NS support and they are actively looking into it. However in the mean time, I found a "workaround" for the webstore. When I set the webstore to have shipping address required and the item(s) are set to "Can be fulfilled and received" the shipping address is carried over to the sales order
m
Interesting, thanks Eric. I ended up just setting the shipping address multiple times. Feels like a quantum mechanics/shrodinger's cat type of thing where checking the record was actually re-initializing it and wiping out my changes
😂 1
e
Same here. The biggest concern I have / had with this type of work around (which I did as well for a while) is what happens if one of my users uses a one time "custom" address instead of one stored on the customer profile? The correct solution would be to see if the Sales Order was sourced from Estimate and if there is a mismatch between the Billing or Shipping address do an update. IMHO this is way to much overhead for what should be the expected behavior from NetSuite
m
All of our sales orders use custom addresses and there are no Estimates, we just start from the sales order / purchase order in netsuite with a custom shipping address on every one (billing address is initially sourced from customer but may be overwritten) created via a restlet
e
We store them with out customer records for mining purposes and other reasons. SO during checkout they are saved to the profile.