- 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 02:33 PM
Hello,
I am assuming that this should be a UI page client controller code .
In client controller we are not supposed to do glide record instead of that please try using setvalue as g_form is accessible in client script and at last you can use g_form.save() to save the form
OR
Best way is to call a glide Ajax and use a script include pass the above two values and the sysid of the current record that you are trying to set values for and update it there in script include using same glide record by querying with received current record sys id. This will work for sure
Please mark my answer correct if it helped you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2022 02:37 PM
thanks for the answear , i was using g_form but I was unable to make it work , gr.update () duplicates the record but at least does something hahaha maybe I did it incorrectly , how would i implement g_form here please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2022 02:47 PM
okay can you confirm whether this UI page is being called while click of a UI action on a form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2022 02:48 PM
yes a pop up is called and it asks for the 2 fields to be filled , after clicking "ok" , the page redirects to the UI page and a duplicated record is shown