Insert New Record and Update Current in Same UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2020 07:28 AM
I am attempting to write a UI action that inserts a new incident, and then goes back and updates the current incident. I can't seem to get it to update the State and Hold Reason fields, but everything else is working as intended. Is there an obvious flaw in my code that I'm missing, or does this need to be handled differently?
//Client side 'onClick' function
function escalateIncidentPrchk() {
var ans = confirm('Are you sure you wish to escalate this incident? This action cannot be reversed.');
if (ans == true) {
gsftSubmit(null, g_form.getFormElement(), 'escalate_inc');
} else {
return false;
}
}
//Code that runs without 'onClick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
escalateIncident();
//server side function
function escalateIncident() {
var gr = new GlideRecord('incident');
gr.initialize();
gr.caller_id = current.caller_id;
gr.location = current.location;
gr.contact_type = current.contact_type;
gr.impact = current.impact;
gr.urgency = current.urgency;
gr.short_description = current.short_description;
gr.description = current.description + ('/n/nThis incident was created as an escalation from Incident: {1}. Please see the parent incident {0} under the "Related Records" tab for more information.', [gr.number, current.number]);
var sysID = gr.insert();
current.state = 3;
current.hold_reason = 10;
current.parent_incident = sysID;
var mySysID = current.update();
if (global.JSUtil.notNil(sysID)) {
gs.addInfoMessage(gs.getMessage('Incident {1} escalated from {0}', [gr.number, current.number]));
}
action.setRedirectURL(gr);
action.setReturnURL(current);
}
Thanks in advance!
Robbie
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2020 08:33 AM
Hi Robbie,
Can you try passing the values in quotes. Like, current.state = '3';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2020 09:11 AM
Jaspal (and Ankur),
I figured out what's going on. The default Parent/Child relationship scripts are setting the states (like they should be, I just wasn't thinking). So my code does set it to On Hold, but then it gets overwritten by the parent/child scripts.
I'm going to tackle this another way. Thank you for the help!