Can someone please explain me UserEvent, BeforeSub...
# suitescript
r
Can someone please explain me UserEvent, BeforeSubmit and AfterSubmit functionality and how it impacts a record? We have a Userevent script on sales order, if the sales order linecount is more then 30, we are calling Map reduce script to create the billing schedule record for each line, if its less then 30 we are creating billing schedule record in userevent itself. (to handle governance usage) . Complete functionality in userevent is in aftersubmit, what's happening is due to nature of sales order being too big, MR is through unexpected error when its trying to save the sales order. Upon raising the case with Netsuite they are suggesting to move the functionality to before submit, wouldn't that cause record has been changed error? Sales order is of 5000+ lines. It takes quite some time to save. Now since we have MR script in aftersubmit, once the record has been saved only then MR will be called and created billing schedule record and then update the sales order. But if we move the calling of MR script in beforesubmit, once the MR is triggered and starts running, the record saving might still be processing, wouldn't it take old Sales Order record and through record has been changed error?
b
changes to the newRecord before submit are before the record has been submitted to the database, so the record hasnt been changed yet
so no problems there
changing the record after submit means you need to load and save it again, which basically doubles the time it takes to save the record since you submitting it twice, once for the original save, another for the one after submit
you would not actually want to use N/task in the beforeSubmit, that runs the risk of the map/reduce running while the user event is still running
r
Now if I call the MR script in beforesubmit, and the MR is triggered before the record can be committed to the DB as the Sales order is very big.
b
so expect to split up your current functionality so that you make changes to your order in the before submit and use the after submit to task your map/reduce
r
we don't have anything else in aftersubmit if the sales order is less then 30 lines, we are creating billing schedule record, if the sales order is more then 30 line we are calling MR script, thats all
t
Sorry to bump in battk, but I am curious why they are building so many billing schedules. 5000 or so per sales order and then multiple sales orders, my god.
👍 1
r
Can't do anything about client requirement per se. Even have suggested to reduce the sales order line of count, they are creating sales order as big as 10000 lines, loading them takes forever. But they are not ready to accept the suggestions. Regardless, battk, how can I solve it? Netsuite is saying due to too many load and save operation the MR script is throwing an error. we are loading the sales order only thrice, and saving only once. Loading once in Userevent, Aftersubmit Loading once in Map/Reduce, get Input Stage Creating all the billing schedule records in Map stage, but not tagging them to Sales order in Map. Loading once in Map/Reduce, - summarize Stage Saving once in Map/Reduce, - summarize Stage
b
you have vastly overestimated the ability to make changes to a sales order with 10k lines
r
have kept the MR as optimized as possible. for each line we are using some unique key for which the Billing Schedule will be created and once all the processing of creating billing schedule records in map stage is done, Iterating through the sales order line and linking the billing schedule record with sales order and saving it.
no other suggestion beside asking them to creating small sales order? Just want to be sure.
t
I think NS recommends transaction lines upto 500, which can go to 1000 in CSV imports, but 10000 lines are enormous. This degrades the user experience.
At this point, I would say most customizations can fail. I did an integration with a govt. Portal where they were accepting max 100 lines, so I had to group in some way to make it work.
r
I know, literally not recommending more then 600 lines to any transaction record to any customer. But when the client is not ready to listen, can't do much about it. There are some orders which they are creating through CSV upload, which they can't even load in Google Chrome, have to use mozila firefox to open such orders, even chrome is having some limitations it seems.
wow 1
lmfao 1
t
I think you should keep the MR deployed on AS, and optimize your code in that. Get all the lines from SO in GET stage, create Billing schedules in MAP, and then collect id’s of them, and pass it to REDUCE and save on SO in just one operation. (assuming you are doing multiple saves. )
I personally won’t even create 30 billing schedules in UE, would limit up to 5-10, and offload it to MR.
r
We will not have enough open deployments to process if we keep it below 30. And MR is optimized, had personally written it. Doing one save only but doing it in summarize stage, not reduce. Rest is same as you suggested.
t
You can ask them to upgrade service tier, or purchase additional suitecloud plus licences, if they are dealing with this much big data.
r
will see, but current problem is not happening for sales order with 30 lines, so for now we can let it be. For big sales order will ask them again to reduce the lines. Thank you both for your inputs.
🙌 1
e
What is being updated in the sales order?
b
hes probably updating item lines with billing schedules
hopefully not using something like findSublistLineWithValue that will search every line for every billing schedule
e
That would be my guess too. I'd probably create a custom record to link the SO/line to the billing schedule and leave the SO alone
b
billing schedule is an actual column on the item sublist that affects billing
e
So there is a native field that gets updated? I haven't used that record before
b
probably, havent seen his code
330 Views