getLocks (UserManager)

The tool tip indicates that this function generates a dataset, so I’m guessing that means,

var ds = databaseManager.createEmptyDataSet(0, 0);
ds.getLocks();

Suppose two users want to access the same record at the same time. One needs to be locked out. So when the second user tries to open the form, do I need to do something like,

for (var i = 1 ; i <= ds.getMaxRowIndex; i++) {
     if((ds.getValue(i, 5) == fs.record_id) && (ds.getValue(i, 4) != globals.currentUser_id)) {
          alert("This record is already in use by " + ds.getValue(i, 4) + ". ");
          break;
     }
}

If this is the case, suppose there are 1500 users on the system at a particular time. Wouldn’t this type of loop evaluation become very inefficient?

Thank you,
Don

Hi Don,

I guess that’s why optimistic locking is preferred over pessimistic locking but if you really need to lock the record then allways try to keep the lockout time as short as possible.

Regards,
Omar

Hi Omar,

I’m planning to let them work on the same record simultaneously in high-traffic areas. In other areas, however, the admins will want to lock out others who might want to edit at the same time.

I was worried about having a large loop test. In 4D there is a “find in array” command that is faster than looping; I can first match against the ID number, and then find the user name(s).

Thanks for the reminder about locking types,
Don