0

I am having a problem with multiple users editing a single record at the same time and losing work when the other person saves the record with their own work. I would like to lock editing when a user is editing a record, and for some reason, records in NetSuite are not single access only by default. How can we accomplish this?

John
  • 302
  • 2
  • 23

1 Answers1

5

You need to create your own locking mechanism.

  • Create a custom table with record id and lock time and user, and expiration time.
  • User event script that puts the record, time and user in the lock record.
  • User event script that checks the lock record on load and redirects other user to view only screen with a message (I append a query parameter to the redirect)
  • A client script keep-alive that pings the lock record with a new expiration time every X minutes while the user is still on the record.
  • A user event script that clears the lock record.
  • A clean up scheduled script that clears the lock record with expired keep alives.
bknights
  • 14,408
  • 2
  • 18
  • 31
  • Okay, this was something I was thinking about, but I worried about the clearing of the lock since a user could either click the Save button or simply just close the window. I'm not quite sure how to make that keep-alive script, but it sounds logical. Though I will say this all seems quite convoluted to implement. – John Nov 12 '15 at 23:20
  • 1
    Lots of steps but you are just touching a few fields. To avoid time issues make sure you store your expiration times as timestamps (`new Date().getTime()`) rather than as Netsuite datetimes. The keep alive is just a standard client javascript. I'd probably use `setInterval` in the pageInit script. – bknights Nov 12 '15 at 23:25
  • Very nice. Thank you! Can you elaborate on the purpose of the redirect query parameter? – sbkp Dec 03 '15 at 18:46
  • The query parameter on the redirect would need to be "read" by a client side script.This would pop a message when the record is loaded to the effect "This record is locked because it is currently being edited by another user...." – bknights Dec 03 '15 at 19:14
  • Gotcha, thanks. I'd been considering how to do this myself and just hadn't thought of the keep-alive client script piece. In your experience, do you have a recommended value for X (keep-alive time) and for a TTL before clearing out the lock in the scheduled script? Do you delete the lock records? I would imagine so, as the number of locks in the system would otherwise grow quite large and performance would degrade on searches. – sbkp Dec 03 '15 at 19:17
  • X depends on your environment. In a call center app you'd expect the user is busy so I might take the record away in a minute. If the user's process once they are in front of the record is lengthy (e.g. they talk with their hands off the keyboard) then 10 minutes might be too short. – bknights Dec 03 '15 at 19:38
  • We have a Fulfillment script in 1.0 that pulls a Serial number from the custom record based on SKU and other parameters. We are working on converting the script to 2.0. What I am unable to figure out is, if the script(say the above functionality is put into Map function for a MR script) will run on multiple queues/instances, does that mean that there is a potential chance that 2 instance might hit the same entry of the Custom record? Is there a better way to accomplish this in 2.0? Also is there a wait I can impleme Thx – tkansara Sep 29 '18 at 13:51
  • You might want to expand your issue in another question. Once you are dealing with server side scripts it is a different set of issues – bknights Sep 29 '18 at 15:03
  • Thanks will post another question. – tkansara Sep 29 '18 at 18:10