Modal UI page is not getting close on Submit

Giampiero1
Tera Contributor

HI All,

i've built a UI page that is called by a UI Action in from the Incident form :

strike_update();

strike_update();
function strike_update(){
	var gm = new GlideModal('strike_update', false, 'modal-lg');
	var strikeNumber= g_form.getValue('u_strike_number');
	gm.setTitle("strike update");
	gm.setPreference('sysid', g_form.getUniqueValue());
	gm.setSize(600, 600);
	gm.render();
}

 

and built a UI Page "strike_update" for store some information that we need. 

in the HTML section there are the OK Cance Button :

<tr>
<td align="left" nowrap="true"><br /><g:dialog_buttons_ok_cancel ok="return validateForm();" cancel="return onCancel();"/>
</td>
</tr>

by Clicking on "OK" button the UI page is not closed but is redirected to the UI page itself in full screen mode. 

function validateForm() {
	var strNumber = parseInt(g_form.getValue('u_strike_number'));
	if (isNaN(strNumber)) {
		strNumber=1;
	}else{
	        strNumber = parseInt(strNumber)+1;
	}	
	if (strNumber>=4 ){
		alert("${JS:gs.getMessage('You are at last Strike')}");
		return false;
	}else {
		g_form.setValue("u_strike_number", strNumber);
		GlideDialogWindow.get().destroy();
	        return true;	
	}
}

Essentially our need is to update some fiekld in the Incident form and close the Modal UI Page remaining on Incident  page

Any hint on this ?

Thanks for your support

7 REPLIES 7

Did you ever figure this out? im having the same issue, after clicking on my custom button:

 

<g:dialog_buttons_ok_cancel id="Buttons" ok="return onSubmit()" cancel="return onCancel()" />
<button id="Buttons" on-click="return worknote()">Add Worknote to Project</button>

 

my form goes to a new page, with the modal full screen and all values are set to null.  the g:dialog_button_ok_cancel works without this behaviour but the Add Worknote to Project button does.

 

i have basic client script, ive even tried to throw the return false to the top of the function hoping it would shed some light on the issue, but alas, the worknotes are not being added via my client script and the page is returning as described, if i move my worknote function inside the submit (removing the return false on the top of the function) the rest of the function works fine, but i dont want to use ok and cancel, the goal is to get rid of those and put in my own buttons.

 

function onSubmit() {
        return false;
}

function onCancel() {
    GlideDialogWindow.get().destroy();
    return false;
}

function worknote(){
	return false;
	var table = gel('project_table').value;
	var sysid = gel('project_sys_id').value;
	var work_note = gel('new_work_note').value;
	var ga = new GlideAjax('add_worknote');
	ga.addParam('sysparm_name',"worknote");
	ga.addParam('table',table);
	ga.addParam('sysid',sysid);
	ga.addParam('work_note',work_note);
	ga.getXMLWait(continueFunction);
	function continueFunction(response){
		//GlideDialogWindow.get().destroy();
		return false;
	}
}

 

Hi Jeffrey

 

The page with empty values you are seeing, is the result of the page submit going wrong.

I would just drop using in the g:dialog_buttons_ok_cancel if you want to use custom buttons anyways.

 

One issue I spotted was your html for your custom button, should be "onclick", not "on-click" to activate the javascript function. Something like this maybe:

 

<button id="Buttons" onclick="return worknote()">Add Worknote to Project</button>
<button id="Cancel" onclick="return onCancel()">Cancel</button>

 

 

And just remember to remove the return false from the top of your worknote function.

 

Br. Mark

Michael_Martin
Tera Contributor

Is your processing script part from the UI Page empty?

I'd recommend adding a message there as well as a redirect back. This could help.

 

in my example.. req_sys_id is a hidden input field in the html form, that stores the sys_id of the current request.
I use that to reload the page after submission and this prevents all sorts of issues.

 

You can add another hidden input called like id=submission and set it in your validateForm client function to submission="submit"; and use that one in the processing part to do server side stuff incl. redirection

if (submission == "submit") {
	yourProcessFunction();
	gs.addInfoMessage("My process is finished..");
}

// redirect back after your code
response.sendRedirect("sc_request.do?sys_id=" + req_sys_id);