Incident Resolve UI Action

Sam Ogden
Tera Guru

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:

find_real_file.png

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

1 ACCEPTED SOLUTION
9 REPLIES 9

Had an attempt at the confirm box instead of the info message but not having any luck, script so far:



function confirmResolve(){
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()){
var conf = confrim("Resolving this incident will resolve all child incidents associated to this log.");
if (conf){
  gsftSubmit(null, g_form.getFormElement(), 'resolve_incident');
}
}
}



if (typeof window == 'undefined')
resolveIncident();




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




I'm fairly new to the scripting side, but not sure how to resolve the above to achieve what we need, any help will be greatly appreciated.



Thanks



sam


I'm guessing that I'm getting mixed up between server and client side.  


I'm not to sure when writing scripts that are using both,


any examples on how to achieve this would be very useful



Thanks


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


HI Sachin,



Thanks for the above,


Rather than create a new UI Action I am trying to amend an existing UI Action.   Before making any changes the script looks like:



find_real_file.png


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



I am struggling to work out in which section I need to add my glide query to see if there are any child incidents that are not closed or resolved, and which section to add in a confirmation pop up which appears if the query returns some results.



If the query find open child incidents the confirmation should appear informing the user that if this log is resolved it will resolve the child incidents.   If the click ok it should continue and execute everything that the ui action currently does.   If they click cancel it should abort the action and make no changes.



Do you have an example of how I could achieve this?



Thanks



Sam


Sam Ogden
Tera Guru