- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2018 08:06 AM
HI All,
I need to make a change to our 'resolve' UI Action on the incident table.
If the log is a parent incident I need it to check that all child incidents are resolved or closed before the parent can be resolved.
I've added the function checkchldinc() to the UI action, but I am not sure how to get this function to run as there is already a function in the onclick field:
function resolveIncident(){
//Set the 'Incident state' and 'State' values to 'Resolved', and display
var mim = g_form.getValue('u_major_incident');
var priority = g_form.getValue('priority');
var appStatus = g_form.getValue('u_approval_status');
if (priority != '1' && mim == "true" && appStatus == "Not Yet Approved")
{
alert ("As this is a Major Incident MIM has to Approve/Reject to resolve the incident");
}
else{
g_form.setDisplay('u_pending_type', false);
g_form.setMandatory('u_pending_type', false);
g_form.setMandatory('comments', false);
var gdw = new GlideDialogWindow('u_incident_resolution');
gdw.setTitle('Resolution Details');
gdw.setPreference('inc_priority', g_form.getValue('priority'));
gdw.setSize(400,300);
gdw.render();
}
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();
function serverResolve(){
current.incident_state = 6;
current.update();
}
function checkchldinc(){
var chldinc = new GlideRecord('incident');
chldinc.addQuery('parent_incident',current.sys_id);
chldinc.addQuery('active',true);
chldinc.addEncodedQuery('incident_stateIN1,8,9,10');
chldinc.query();
if(chldinc.next())
{
gs.addInfoMessage("Please ensure all child incidents are resolved before resolving the parent incident log.");
current.setAbortAction(true);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 06:48 AM
Please check below for client and server code for UI action
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2018 08:12 AM
You need to call checkchldinc() function in your UI action code like below
function resolveIncident(){
checkchldinc();
//Set the 'Incident state' and 'State' values to 'Resolved', and display
var mim = g_form.getValue('u_major_incident');
var priority = g_form.getValue('priority');
var appStatus = g_form.getValue('u_approval_status');
if (priority != '1' && mim == "true" && appStatus == "Not Yet Approved")
{
alert ("As this is a Major Incident MIM has to Approve/Reject to resolve the incident");
}
else{
g_form.setDisplay('u_pending_type', false);
g_form.setMandatory('u_pending_type', false);
g_form.setMandatory('comments', false);
var gdw = new GlideDialogWindow('u_incident_resolution');
gdw.setTitle('Resolution Details');
gdw.setPreference('inc_priority', g_form.getValue('priority'));
gdw.setSize(400,300);
gdw.render();
}
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();
function serverResolve(){
current.incident_state = 6;
current.update();
}
function checkchldinc(){
var chldinc = new GlideRecord('incident');
chldinc.addQuery('parent_incident',current.sys_id);
chldinc.addQuery('active',true);
chldinc.addEncodedQuery('incident_stateIN1,8,9,10');
chldinc.query();
if(chldinc.next())
{
gs.addInfoMessage("Please ensure all child incidents are resolved before resolving the parent incident log.");
current.setAbortAction(true);
}
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2018 08:46 AM
Hi Sachin,
Thanks for the above. just added this at the top , but now my UI action is not doing anything?
Thanks
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2018 08:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 02:34 AM
Hi All,
I've got my UI action currently set as below. I want it to check that any child incidents on the log have been resolved or closed (function checkchldinc)
Currently when I try this UI action nothing happens, not sure where I have gone wrong?
Also is there away to change the addInfoMessage to be an ok or cancel box. If user selects ok then it proceeds to resolve the incident. If they select cancel it aborts the UI action?
Any help is greatly appreciated.
Current UI Action Script
function resolveIncident(){
checkchldinc();
//Set the 'Incident state' and 'State' values to 'Resolved', and display
var mim = g_form.getValue('u_major_incident');
var priority = g_form.getValue('priority');
var appStatus = g_form.getValue('u_approval_status');
if (priority != '1' && mim == "true" && appStatus == "Not Yet Approved")
{
alert ("As this is a Major Incident MIM has to Approve/Reject to resolve the incident");
}
else{
g_form.setDisplay('u_pending_type', false);
g_form.setMandatory('u_pending_type', false);
g_form.setMandatory('comments', false);
var gdw = new GlideDialogWindow('u_incident_resolution');
gdw.setTitle('Resolution Details');
gdw.setPreference('inc_priority', g_form.getValue('priority'));
gdw.setSize(400,300);
gdw.render();
}
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();
function serverResolve(){
current.incident_state = 6;
current.update();
}
function checkchldinc(){
var chldinc = new GlideRecord('incident');
chldinc.addQuery('parent_incident',current.sys_id);
chldinc.addQuery('active',true);
chldinc.addEncodedQuery('incident_stateIN1,8,9,10');
chldinc.query();
if(chldinc.next())
{
gs.addInfoMessage("Please ensure all child incidents are resolved before resolving the parent incident log.");
current.setAbortAction(true);
}
}