Is there a simple way to lock a record during sync...
# suitescript
m
Is there a simple way to lock a record during syncing it with an external system? I know I can do it using a userevent script, but I don't want to write one for each case, I was wondering if the scheduled script I am using for syncing can do it.
b
User event scripts can deploy to all records
m
I think I didn't really articulate what I wanted... I just felt maybe there is a cleaner solution kind of
transaction.lock()
transaction.unlock()
somewhere. I will create something similar. Thanks ☕
g
just curious, how is this implemented with a UE script?
m
With a custom field (checkbox)... toggle from any script, and the UE should prevent editing if it is checked.
So from the scheduled script in my case, I would load the journal, mark this field as true, save the journal, and load it again (now I can be sure it won't be change during syncing) then extract the data I want to sync, sync it, then uncheck it, and save the journal again.
g
Makes sense. Didn't know if there was a dedicated method for UE.
b
The more performant version is checking and unchecking the checkbox of a custom record associated with the parent record. Custom records are faster to save and will not change the last modified date on the parent record
That said, its unusual to lock records being synched. Implementing the lock usually means the update is lost, which can be extremely annoying. Usually you would want the updated record to sync, not to be ignored and lost
m
It depends ™️ The point here is preventing it from being modified during the process, after this you can keep the lock, if it doesn't make sense for the record to be touched again, or unlock it, to open the door for future modifications, which would be synced again.
But you made me pay attention to the last modified date... hmm.
r
Why does you want to lock it between the sync? How long it takes for the sync to happen and how are you syncing it?
m
@raghav so no one edit it during the process. I don't remember how much time each journal takes, but they usually have thousands of lines, and in order for the request not to timeout, we had to send 50 line only on each iteration. It is just a scheduled script that goes over the lines, send them using N/https, and mark the lines as synced, then pick another 50, and so one, until it marks the journal as a whole as synced.