Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Why is gr.update() duplicating the current record and not updating?

Ulrich Matthew
Tera Contributor

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;
}

1 ACCEPTED SOLUTION

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

View solution in original post

32 REPLIES 32

i wrote that gs.info inside the if and is not showing 

 

find_real_file.png

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

IT WORKED!!!! THANKS A LOT 

just onoe quick question , when I click "ok " on the UI page pop up it redirects me to the UI page again like this 

 

find_real_file.pngfind_real_file.png

do one thing 

replace location.reload() in your client script with this line 

GlideDialogWindow.get().destroy();

Please mark this answer helpful if it helped you

thanks it worked , but there's a small detail hahahaha sorry for asking this much , the UI action that is being called in the client script , is not being executed unless I deactivate the UI page 

 

like this 

 

function onSubmit() {
	var conf;
	if (g_form.getActionName() == 'approve_new_employee') {
		conf = confirm('Please confirm account New Employee Approval');
		return conf; // Updates the database if confirmed, aborts if canceled
	} else if (g_form.getActionName() == 'terminate_employee') {
		var c = this;

		/**/
		if (window === null) {

			var dialog = new GlideDialogWindow('show_termination_reason');
			dialog.setTitle('Resolve');
			dialog.render();
			return false;


		} else {
			spModal.open({
				widget: 'terminate_employees',
				buttons: 'false'
			}

						).then(function(reason) {
				c.reason = reason;
			});
		}


		return false;
	} else
		return true;

}


is weird cause it terminates the employee there 

 

if(gs.hasRole('u_itechag.base_hr_manager_lead')) {

	//If HR Manager, terminate employee with no approval
	current.u_work_status = 'Terminated';	
} else {
	current.u_work_status = 'Terminating';
}
current.update();
action.setRedirectURL(current);