On Resolve wait for GlideDialogWindow to close

Community Alums
Not applicable

So I am building some criteria in to Incidents 'Resolve' UI action. Part of this requires the use of a GlideDialogWindow.

I'm trying to determine how to get the UI action to not execute 

gsftSubmit(null, g_form.getFormElement(), 'resolve_incident');

until after the GlideDialogWindow has closed, any help is appreciated, code for UI action below:

 

function resolveIncident(){
	
	
	
	//Only do these actions if record is not new
	//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
	g_form.setValue('incident_state', 6);
	g_form.setValue('state', 6);
	g_form.setValue('u_sub_status', '');
	g_form.setReadOnly('u_sub_status', true);
	//if not resolved by only providing a kba
	if (g_form.getValue('close_code') != 'Suggested Knowledge Article') {
		if (g_form.getValue('comments') == '') {
			//Remove any existing field message, set comments mandatory, and show a new field message
			try {g_form.hideFieldMsg('comments');} catch(e) {}
				g_form.setMandatory('comments', true);
				g_form.showFieldMsg('comments','Comments are required when resolving an Incident','error');
				g_form.addErrorMessage('Incomplete Mandatory fields exist on the form, please review the form, complete and save');
				return false;  //Abort submission
			}
			//Call the UI Action and skip the 'onclick' function
			gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
		}
		//if resolved by just suggesting a KBA
		else if (g_form.getValue('close_code') == 'Suggested Knowledge Article') {
			var kbCheck = new GlideAjax('kbResolveCriteriaCheck');
			kbCheck.addParam('sysparm_name','verifyAccess');
			kbCheck.addParam('sysparm_caller',g_form.getValue('caller_id'));
			kbCheck.addParam('sysparm_inc_num',g_form.getValue('number'));
			kbCheck.getXMLAnswer(kbCheckResult);
			
			
			function kbCheckResult(response) {
				var answer = JSON.parse(response);
				
				if (answer.noKB == true) {
					alert('Please attach a knowledge article to this incident for the caller before resolving');
					return false;
				}
				else if (answer.noAccess == true) {
					alert('The caller does not have access to view the attached knowledge articles\nPlease select a different article');
					return false;
				}
				else {
					var dialog = new GlideDialogWindow('incident_kb_select');
					dialog.setTitle('Select KB for caller');
					dialog.setPreference('kbList',JSON.stringify(answer.kbList));
					dialog.setPreference('incidentElement',g_form.getFormElement());
					dialog.render();
				}
			}
			//Call the UI Action and skip the 'onclick' function
			gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
		}
		
		
		
	}
	
	//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();
	}
	
	
1 ACCEPTED SOLUTION

Community Alums
Not applicable

So I was overthinking it... I commented out the gsftsubmit on my glidedialog section.. added a g_form.submit to the glidedialogwindow ui page

View solution in original post

3 REPLIES 3

kristenankeny
Tera Guru

Have you tried switching your glideajax callback to run asynchronously?

Community Alums
Not applicable

I wasn't sure if that would help, the GlideAjax just provides data for use by the GlideDialogWindow. 

Nothing gets returned to the GlideAjax from the GlideDialog.

Community Alums
Not applicable

So I was overthinking it... I commented out the gsftsubmit on my glidedialog section.. added a g_form.submit to the glidedialogwindow ui page