Is there a way to lock a non custom record? So whi...
# suitescript
s
Is there a way to lock a non custom record? So while 1 is processing, and another tries to access it, it holds until the other processess is completed?
b
Not that I know of. If you have 2 scripts load and submit a record, the one that submits first will succeed and the second one will fail since there were changes to the record since it was loaded
s
Yup, that's what happening. K, thanks
b
You can catch that error and try again
s
Do you know if there is a way to check and see if a record is processing?
c
non-custom records already do optimistic locking by default so if someone edits something that someone else has edited it'll error out. Trying to write your own locking mechanism is going to be a nightmare
IMO i'd go w/ the built in default
You CAN turn optimistic locking off on custom records though just as an FYI but you can't for standard
s
look at using
_.attempt()
to help manage the potentially expected case of this error
s
k. I'd prefer it to be locked and error. Just need to implament a recursive call to handle this when they send in the same job back to back.
c
so you're trying to prevent duplicates more than a locking mechanism?
s
nah, because if it exists, i'm updating it. it's an AddOrUpdate type restlet
i don't know how the job got sent in twice to be honest, but I would like to handle it if it does
c
is there something unique that you can do a search on before you do anything
s
last modified date may be the only thing. I think what I can do is catch the "record been modified", pause a few seconds, then do a recurrsive call back to the same method.
c
you dont want your restlet to sit and spin though
s
Yeah, it'd only get 1 more try before exiting with the appropriate error
s
you can't 'sit and spin' - or at least NS doesn't provide a mechanism to do so, and you should run up against instruction count limits if you try a NOP loop
c
you certainly can sit and spin if you code it wrong
but it will eventually time out after 45 secs