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

okay then normal g_form.setValue('your field back end name',value); this syntax should work 

and also put alerts of reason and date variables so that we will to know if value is being accessed or not

please try this and let me know

there is a commented section above , which is the way I was trying to call g_form , I think it follows what you just said

g_form.setValue('u_reason', reason);
	g_form.setValue('u_termination', date);

	g_form.save();

(and should work) but is not updating anything

did you try alerting reason and date ?are teh values coming in from HTML ?

yes they come from HTML page , I confirm they are being captured in those variables 

lets try one thing 

in your HTML code do this change

embed your HTML code between these tow tags 

<form>

your HTML code

</form

please try this