- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2022 02:14 PM
When i click on ok, the record I'm working with is being duplicated and not updated
function onCancel() {
GlideDialogWindow.get().destroy();
return false;
}
function onSubmit() {
var reason = document.getElementById('termination_reason').value;
var date = document.getElementById('termination_date').value;
var sysId = g_form.getUniqueValue();
/*g_form.setValue('u_reason', reason);
g_form.setValue('u_termination', date);
g_form.save();
*/
var employees = new GlideRecord('u_itechag_employees');
employees.addQuery('sys_id', sysId);
employees.query();
if (employees.next()) {
employees.u_reason = reason;
employees.u_termination = date;
employees.update();
}
location.reload();
return true;
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2022 03:56 PM
var terminate_employee = Class.create();
terminate_employee.prototype = Object.extendsObject(AbstractAjaxProcessor, {
Terminate:function()
{
var employees = new GlideRecord('u_itechag_employees');
employees.addQuery('sys_id', this.getParameter('sysparm_id'));
employees.query();
if (employees.next()) {
employees.u_reason = this.getParameter('sysparm_reason');
employees.u_termination = this.getParameter('sysparm_date');
employees.update();
}
},
type: 'terminate_employee'
});
Replace the script below and try
please mark my answer correct if it helps you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2022 03:07 PM
Hi,
I dont think gr.update creates a new reocrd as such. Here are few things taht you might have to chck.
1. Disable update from onsbumti and check if it still creating a new record
2. If not, then it means on update there is another insert happening. So check the Business rules once on update of your table and chk.
3. Or the form might be submitting mutliple times bcoz of 2 records getting inserted?
Mark the comment as a correct answer and helpful if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2022 03:10 PM
diabled update and it doesn't create a record or update , when I activate update, it inserts a new record instead of updating the current one ( but keeps the new values in the new record)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2022 03:18 PM
may be your existing record is not being updated. Can you check the sysId once by putting alert
var sysId = g_form.getUniqueValue();
and check if its your existing sysID or a new record sysID.
Also try to check if there is any BRs running on this table u_itechag_employees.