UI Action Call Script Includes to set condition for confirmation box

Sam Ogden
Tera Guru

Hi All,

I am trying to amend our 'Resolve' UI action on the incident form.

I need this to check if the log has any child incidents that are not yet closed or resolved that it prompts the user with a confirmation box before proceeding.

I have currently got the confirmation box to appear - this currently appears every time the UI action is clicked.

I need to now make this conditional so the confirmation pop up only appears if the log has child logs that are not yet closed or resolved.

I'm guessing to do this I am going to have to create a script includes and use a glideajax on the UI action to call this.

I have never done this before and not totally sure how to.

I've created a script include as:

find_real_file.png

My UI Action is:

find_real_file.png

find_real_file.png

I'm not sure how to add the glideajax in the client part of the script in order to only show confirmation box if the script includes returns 'true'

Any help is greatly appreciated

Thanks

Sam

1 ACCEPTED SOLUTION

andymcdonald
Kilo Guru

Hi Sam - your SI needs to be created with the Client Callable box checked, which will cause it to extend AbstractAjaxProcessor, so it can be called from the client.   You will then call your function as follows:


var ga = new GlideAjax('name of your SI');


ga.addParam('sysparm_name', 'name of the function in SI you want to call');


ga.getXMLWait();


var resp = ga.getAnswer(); // this is the value being returned from your function.


View solution in original post

7 REPLIES 7

andymcdonald
Kilo Guru

Hi Sam - your SI needs to be created with the Client Callable box checked, which will cause it to extend AbstractAjaxProcessor, so it can be called from the client.   You will then call your function as follows:


var ga = new GlideAjax('name of your SI');


ga.addParam('sysparm_name', 'name of the function in SI you want to call');


ga.getXMLWait();


var resp = ga.getAnswer(); // this is the value being returned from your function.


Hi Andrew,



Thanks for the above.   I've just tried to add the above into my scripts, but when I select the 'resolve' UI action on a log with a child incident or on a log without a child incident nothing is happening.



Any help where I am going wrong is greatly appreciated.



Script includes:



find_real_file.png


UI Action:



find_real_file.png


function resolveIncident(){
var ga = new GlideAjax('childIncCheck');
ga.addParam('sysparm_name', 'checkLog');
ga.getXMLWait();
var resp = ga.getAnswer();

if(resp == true){
var con = confirm('Resolving this incident will resolve all the associated child incidents for this log.');
if (con){
 
//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();
}
}
}
else {
  return false
}
}


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


Hi Andrew,



Managed to get this working - noticed a number of errors but now working as I wanted.   Thanks for your help, was much appreciated.



Sam


Way to go man!