Hey! Good morning and happy new year all. I am cur...
# suitescript
m
Hey! Good morning and happy new year all. I am currently working on a User Event that needs to change the Subsidiary of a transaction (invoice at the moment), when I go and change the subsidiary on beforeSubmit I get an Unexpected Error, has anybody ever ran into an issue like this?
n
Might be an idea to share your code since the error message is non-specific.
m
Good idea, sorry I did not provide that before, here's the code, I have simplified it for the sake of the example:
Copy code
const beforeSubmit = (context) => {
    if (context.type == context.UserEventType.CREATE || context.type == context.UserEventType.EDIT) {
      let record = context.newRecord;

      record.getValue('subsidiary'); // returns 1

      record.setValue({
        fieldId: 'subsidiary',
        value: 2 // Hardcoded for the example
      });
Keep in mind subsidiary is currently set to 1 if i were to do record.getValue('subsidiary')
digging deeper, it looks like after setting the new subsidiary sets it on the header level but not on the line level
l
do you have “Multi Subsidiary Customer” enabled and your customers has both subsidiaries on it?
m
hey @Luiz Morais, my customer has both subsidiaries on it that setting is on, yes
i think the problem lies in the beforeSubmit record not being in dynamic mode and therefore not updating the lines with the new set subsidiary
l
that make sense once updating subsidiary will update tax calculations, location, etc
is record being created/updated by another script?
m
no, I am creating it through the UI 😕
l
in this case it’s in Dynamic mode
m
my understanding is that if it's a user event and we are on beforeSubmit, no matter what the context is (UI / Script) it will be on non dynamic mode, but I could be wrong on that one
t
@Matias Bonifacino afaik subsidiary cant be changed after the initial save, maybe that is causing you problems? you can debug like this - turn off your script edit existing transaction ctrl+shift+i on chrome or rightclick inspect > console or open console: nlapiSetFieldValue('subsidiary',2); hit enter, save, and you'll get unexpected error
👀 1
m
@Timothy Wong that is correct, u cant change it after the initial save, this User Event is running on Create though (sorry for the confusion I see my snippet has an or for if it's edit)
one thing I did see though is that if i go to create the invoice on the UI, add my line item, add my subsidiary to 1 and a location and customer, then change my subsidiary my line items are gone, my guess is something is going on there, but I wish the Unexpected error was throwing out more details 😞
t
@Matias Bonifacino the order matters in dynamic mode because it mimics NetSuite on the UI. So a bit of a small recommendation is follow the script processing "field wise" as you/user would filling it in the UI. Then the sourcing happens, then it will start to work. e.g.. order to cash, fill in entity, it'll fill in subsidiary, if you dont do that or subsidiary is empty, you cant fill in item lines. that's.. netsuite for you. From that, It sounds like you need to rearrange the order of events in your current script and it might work. Happy debugging!
👏 1