Preventing multiple users updating the same record.

kevsandberg
Tera Contributor

I am attempting to prevent multiple users updating a record at the same time.

For instance two members of the Service Desk open the same record and update the record - only certain elements of the first users save will be maintained.

I found the following script on the Wiki , and this seemed to be exactly what I was looking for:

function onSubmit() {
var updatedOn = gel('onLoad_sys_updated_on');
if (!updatedOn)
return;

updatedOn - updatedOn.value;
if (!updatedOn)
return;

var sysid_gel = gel('sys_uniqueValue');
var sysid = sysid_gel.value;
var gr = new GlideRecord('incident');
gr.addQuery('sys_id',sysid);
gr.query();
if (gr.next()) {
var dbUpdatedOn = gr.sys_updated_on + '';
var dbUpdatedBy = gr.sys_updated_by + '';
} else
return;

if (updatedOn != dbUpdatedOn) {
return confirm("Record has been updated by " + dbUpdatedBy + " since you opened it - "
+ "overwrite those changes with yours? Note that Additional comments and Work Notes are "
+ "additional and would not be overwritten.");
}
}

However - the problem I have is it is causing the message every time an Incident is opened and not just when someone else has accessed it before you.

Has anybody else had this problem with this script?

Thanks,

Kev

2 REPLIES 2

kevsandberg
Tera Contributor

This is the Wiki document in question.

http://wiki.service-now.com/index.php?title=Creating_an_Alert_to_Prevent_Simultaneous_Record_Updates

Thanks.


Hi,

I am also facing the same issue that you had.
Please tell me how did you handle this issue.
Also, can you explain what is the meaning of [onLoad_sys_updated_on], this is not a dictionary fied.