Hey everyone. I switched jobs back in December and...
# suitescript
j
Hey everyone. I switched jobs back in December and I'm not working with NS anymore, but my old employer reached out because a script that I deployed doesn't seem to be working anymore. They can't nail down a date, but my guess is that it stopped working when 2020.1 was released. Is there anything in this script that jumps out as not supported? This runs when there's a field changed on the Shipping Method. It only runs when "Customer Pick Up" (internal id 16853) is selected. It grabs the SO's location, uses its address to create a custom shipping address, then uses it to set the Shipping Address on the SO.
function setCPUshipto(type, name, linenum) { if (name !== "shipmethod" || nlapiGetFieldValue("shipmethod") !== "16853" || nlapiGetFieldValue("location") == "") { return; } var locationId = nlapiGetFieldValue("location"); var locationLookup = nlapiLookupField('location', locationId, ['address.countrycode', 'address.attention', 'address.addressee', 'address.address1', 'address.address2', 'address.city', 'address.state', 'address.zip']); var subrecord = nlapiCreateSubrecord("shippingaddress") || nlapiEditSubrecord("shippingaddress") subrecord.setFieldValue("country", locationLookup['address.countrycode']); subrecord.setFieldValue("isresidential", "F"); subrecord.setFieldValue("attention", locationLookup['address.attention']); subrecord.setFieldValue("addressee", locationLookup['address.addressee']); subrecord.setFieldValue("addr1", locationLookup['address.address1']); subrecord.setFieldValue("addr2", locationLookup['address.address2']); subrecord.setFieldValue("city", locationLookup['address.city']); subrecord.setFieldValue("state", locationLookup['address.state']); subrecord.setFieldValue("zip", locationLookup['address.zip']); subrecord.commit(); }
I think everything is working up until the commit. I threw some console.log's into the script and it looks like the locationId and locationLookup are correct.
I'm not sure about the subrecord. I'll attach the log.
Console log for the CPU script
@battk I think you helped with this script last June. Any thoughts on this?
b
ran the code, it sets the fields on the shippingaddress subrecord, but updates the fields after the transaction is saved
j
it used to update the field immediately, which was the necessary solution.. they're running avatax, which requires that the field be correct when it's saved (for tax calculations)
b
might want to check if the tax are still correct
j
Hmm.. I don't think it's working the same for me. I entered an SO and had it use a shipping address in KS. Then edited the order, changed the method to Customer Pick Up, saved again. It did not update the shipping address on save.
b
the displays are wrong
but the address related fields should be set
j
gotcha - let me try again
b
try something like
Copy code
nlapiViewSubrecord('shippingaddress').getFieldValue('addr1')
to check the data
j
i realized my error in the previous test.. just did it again with different states, and you're absolutely right - the tax is updating by the display isn't
i just printed the SO and it has the updated address, which makes sense - it pulls from the record
i wonder why the screen isn't updating anymore.. even with an additional edit/change/save, it shows the incorrect address on the screen
b
probably check with netsuite support
j
awesome thank you again