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

Hi Sam, 

I am after something very similar to this and struggling to get it working. Is there any chance you can post your code for this so I can use it as a base for mine. Any help would be great. Cheers.

Hi Alex,

We have this setup as follows:

UI Action:

find_real_file.png

UI Action Script:

function resolveIncident(){
	
	var numb = g_form.getValue('number'); // set to sysid of parent

	var ga = new GlideAjax('childIncCheck');
	ga.addParam('sysparm_name', 'checkLog');
	ga.addParam('sysparm_numb', numb);
	ga.getXMLWait();
	var resp = ga.getAnswer();
	
	if(resp == 'true'){
		var con = confirm('This incident has open child incidents associated to it.  Resolving this incident will also resolve these child incidents.  Are you sure you want to proceed?');
		if (con){
			resolveLog();
		}
		else {
			return false;
		}
	}
	else if (resp == 'false') {
		resolveLog();
	}
	else {
		alert("Incident Parent Check Error! - please screenshot and send to an admin");
	}
}

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

Script Includes - Client callable is ticked:

var childIncCheck = Class.create();
childIncCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	checkLog : function() {
		
		var incNumb = this.getParameter('sysparm_numb');
		gs.log('samtest '+incNumb);
		var childinc = 'false';
		
		var gr = new GlideRecord('incident');
		gr.addQuery('number', incNumb);
		gr.query();

		if(gr.next()) {
			gs.log('found record ');
			var parCheck = new GlideRecord('incident');
			parCheck.addQuery('parent_incident', gr.sys_id);
			parCheck.addQuery('active',true);
			parCheck.addEncodedQuery('incident_stateIN1,8,9,10');
			parCheck.query();
			if(parCheck.next()){
				childinc = 'true';
				gs.log('found parent');
			}	
		}
		gs.log("return value: " + childinc);
		return childinc;
	},
	
	type: 'childIncCheck'
});

 

Let me know if there is anything else you need.

Thanks

Sam

Thanks for that Sam. Appreciate it.