hey experienced devs. when multiple submissions of...
# suitescript
l
hey experienced devs. when multiple submissions of the same suitelet are running at the same time, how to make sure no processing of the same record? is there a global variable/lock or some sort to tell other executions that I'm working on this, nobody else touch it?
c
There'e nothing built into NS to stop that from happening
You can build a locking mechanism yourself through the use of boolean fields.
Although I'm not a fan unless it's really necessary. I would start by looking at the overall technical architecture of the solution.
l
where should that bool lock be saved so that multiple executions can both access?
c
It entirely depends on the specifics of what you're doing.
I would fight tooth and nail to remove the need to do this in the first place
l
say suitelet pulls a list of quotes, users check mark on lines and suitelet makes orders. multiple users may submit the form at the same time. a quote may just happen to be in two batches for processing. we don't want two sales orders created
e
I think you'll need some sort of queuing system for these requests; trying to build your own database locking mechanism feels wildly impractical.
l
hmm... netsuite built in suitelets are everywhere, they don't have dups. approve orders, approve invoices, something about fixed asset JE... never heard of them creating dup records. they must be doing something
e
Have you tested those? What happens if two people approve the same order simultaneously? The result of simultaneous submissions isn't always dupe records
l
no i haven't. maybe they are. for approvals, it doesn't matter if double approved. if the suitelet creates new record, that would be bad.
e
If a Quote has been transformed to a Sales Order, the Sales Order will have a Created From filled out. When you go to transform a Quote, if you can find a Sales Order created from that Quote, you should abort the transformation.
That assumes 1:1 Quote:Order, though.
l
true
c
You could probably keep some unique identifier on the quote and SO. When you create an SO you create the value, if that value exists in a list on the Quote, don't create the SO.
so you can be quote 1:* SO
l
how about map reduce. if there are multiple submits to a map reduce, does it process sequentially or parallel is also allowed
e
Parallel would certainly be possible
How likely is this scenario?
l
not very. but it does happen🤣
e
And it's pretty bad if it does. Rather than trying to solve the potential races, I think you're going to want to queue up the requests and then process them in a batch so that the list of requests can be deduped before processing. This is a pretty common pattern I use and see in integrations
l
yes. a single queue will certainty work. it would be slow though. cant have both.
e
Correct. It would be slower. Whether it would be too slow is the important question though.
l
thank you all for sharing ideas
a
If the ultima goal is to avoid dupes your quickest and safest bet would be to use
externalid
(our of the box designed to prevent exactly that), you only set that when records are being created and you are done.
☝️ 1
b
The SAFE guide goes over race conditions in section 4.7 SuiteApp Designs and Concurrency Issues
c
To work around the issue of other processes not honouring the semaphore, you can create a beforeSubmit (on the target transaction) that checks if a semaphore record exists and disallows a save if one is found. The external ID has to be a well defined composite key for the beforeSubmit to reliably re-create the id on the semaphore record though.