How to lock a record in Netsuite in Suite Script 2.0 and Suite Script 1.0 when particular user works on that and unlock when current user is done with record?

Hi All,

As Netsuite is a online tool many users can login with different login ids and work at same, because of that some times 2 people works on same record same times and gets error "Record Has Been Changed".

There could be many ways but today I am going to write about one way which I implemented with some assumption.If you think of some other methods them please comment below under comment section.

Step 1. Have a custom record to store who is viewing or working on which record.
Step 2. Apply Lock on Record and Save the key-id pair to custom record .
Step 3. Work done then release the lock.

Note: There are few assumptions .
1. This is for employees only.
2. They will work on some record and complete it with in certain time .
3. They will complete and save record.

Step 1: Custom record creation:
         I created a custom record with fields for storing Employee List, Record Type, Record Id,  Date and Time field , Is Locked - checkbox.

Step 2: Apply Lock:

         Write a user event script which will search customer record and see if current record is locked or not, if Locked script will show a message and redirect to read mode i.e unable to edit.

         If record is not locked then script will create a custom record on edit of record and enter employee who is currently logged in , date time, is locked is T, and other details.
       Use Lock record api to lock the record and allow only for employee.
      
Step 3:Release Lock :

      Now comes tricky part. There are chances that they click on cancel , or close browser window or back to history or Save record etc.
     We have to handle all these situation if we need fully automated process.
      In Javascript we can over ride the method, so view source and search for beforeunload event function 
it should be like this :
window.onbeforeunload = page_unload;
So here page_unload is the main function of netsuite which they are using for throwing 
Alert when someone change something and did not close.
We will use it to unload the record. This way when someone go out from the page's current 
then this method will unlock the record and keep it ready for next person to use.

This method will work but there is one more scenario, what if power cut or internet got
disconnected and not event triggered?

Write a Schedule script to unlock any lock which is there for 30 min, add logic to see current server time and the time on the custom record, if it is more than 15 min then proceed and unlock the record.

Always use server date and time , because if we use user's date and time then that can be different but server time will be one. 

You can also add a button to release lock , only show the release lock button if that record is currently locked .

Please let me know what you think about current approach, there could be multiple approaches , if you use some other way or think of some other way do comment below.

Thanks
Abhi
   
  
           

Comments

  1. Hi,

    How do you use the page_unload function to unlock the record?

    ReplyDelete
    Replies
    1. Hi There,
      On Page Unload you can write client script which will search if record where record is locked checked and script will release that lock.
      Use custom Record to manage locks.
      2nd way is write a schedule script and remove lock after some time.

      Delete

Post a Comment

Thanks for you message, please join us on Facebook and Linkedin