Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Modal UI Page redirecting to itself on OK or Cancel

Kai Tingey
Tera Guru

Hi All

 

I am working on a UI action to allow itil staff to create a new caller if the person doesn't exist in the sys_user table. it all works well, except my modal UI page redirects to itself on submit and on cancel.

 

I am using 

 

 

<g:dialog_buttons_ok_cancel ok='okButton()' cancel='processCancel()'/>

 

 
and my processCancel() function just does this:

 

//Cancel button script
function processCancel(){	
 GlideDialogWindow.get().destroy();
	   
}

 

 

After my dialog spawns, if I hit either OK or Cancel

 

KaiTingey_0-1689138966890.png

 

 

it then redirects to a version of itself in a full screen:

KaiTingey_1-1689139020874.png

I've tried using gs.setReturnURL and gs.setRedirectURL and a few other things i've found via google, but the behaviour never changes.

 

full scripts below:

 

UI Page:

 

HTML

 

 

	<g:evaluate var="jvar_taskId" expression="RP.getWindowProperties().get('sysId')" />
	<input type="hidden" id="hidden_sys_id" value="${jvar_taskId}"></input>
	  <g:ui_form>
	<table width="700">
		<tr>
			<td>
				<g:form_label>Enter User's Name</g:form_label>
		    </td>
			<td>
            <g:ui_input_field label="" name="extusr_name" id="extusr_name" mandatory="true" size="40"/>
            </td>
        </tr>
		<tr>
			<td>
				<g:form_label>Enter User's Phone Number</g:form_label>
		    </td>
		    <td>
            <g:ui_input_field label="" name="extusr_phone" id="extusr_phone" mandatory="true" size="40"/>
            </td>
        </tr>
		<tr>
			<td>
				<g:form_label>RIW Number</g:form_label>
		    </td>
		    <td>
            <g:ui_input_field label="" name="extusr_riw" id="extusr_riw" mandatory="true" size="40"/>
            </td>
        </tr>
		
		<tr>
			<td>
				<g:form_label>Enter User's Company</g:form_label>
		    </td>
		    <td>            
			<g:ui_reference label="" name="extusr_company" id="extusr_company" table="core_company" mandatory="true"/>
            </td>
        </tr>
		
		
		<tr id="dialog_buttons">
<td colspan="2" align="right"><!-- Pull in 'dialog_buttons_ok_cancel' UI Macro for submit/cancel buttons. 'ok' option will call the 'validateComments' Client script function from the UI Page-->
	<g:dialog_buttons_ok_cancel ok='okButton()' cancel='processCancel()'/>

	</td>
</tr>
	</table>
	</g:ui_form>

Client Script:

 

//OK Button script goes here

function okButton(){
	var sysid = hidden_sys_id.value;
	var name = extusr_name.value;
	var phone = extusr_phone.value;
	var company = extusr_company.value;
	//var manager = extusr_manager.value;
	var riw = extusr_riw.value;

//time for some AJAX
var ga = new GlideAjax('newExtUser'); 
    ga.addParam('sysparm_name', 'createExtUser'); //ajax function
    ga.addParam('username',name); //pass name into ajax
    ga.addParam('userphone',phone); //pass phone
    ga.addParam('usercompany',company); //pass company    
    ga.addParam('userriw',riw); //pass riw number
    ga.addParam('hidden_sys_id',sysid); //pass sysid into ajax
    
    ga.getXML(myCallBack); //process response
}

function myCallBack(response) { 
   //Dig out the 'answer' attribute
   var ajaxcomplete = response.responseXML.documentElement.getAttribute('answer'); 
    alert(ajaxcomplete); //alert the result to make sure all is well.
    GlideDialogWindow.get().destroy(); //Close the dialog window
    
}



//Cancel button script
function processCancel(){	
 GlideDialogWindow.get().destroy();
	   
}

 

 

 

5 REPLIES 5

Nicolas Piveta
Kilo Sage

Hey @Kai Tingey ,

 

Usually it works just by adding this after the "destroy()" in the UI action

action.setReturnURL(current);

 

I know you said "gs.setReturnURL and gs.setRedirectURL" 

try using action instead gs.

if it helps let me know 🙂

 

Regards,
Nicolas Piveta

Hi Nicolas,

 

Thanks for the response. Unfortunately that didn't work either. I've tried action.setReturnURL(current) and action.setRedirectURL(current)

 

i also tried 

action.setRedirectURL("./incident.do?sys_id="+sysid); 
and a few small variations (removing dots and slashes ) to see if i could force it back to the incident record - but it bluntly refuses to do anything but show the modal form in full screen.

erck
Tera Contributor

Did you find an answer for this ?

yes it is working now.


I basically just re-did the entire thing from scratch and it worked. If i had to guess what part of it was causing the problem, is that in the new version i left the jelly code in the HTML - i think I stripped it out the first time because i didn't think i needed it.

HTML:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g:evaluate var="jvar_taskId" expression="RP.getWindowProperties().get('sysId')" />
	<input type="hidden" id="hidden_sys_id" value="${jvar_taskId}"></input>

<table style="width:700px;">
		<tr>
            <td>
                <g:form_label>Enter User's First Name</g:form_label>
            </td>
            <td>
            <g:ui_input_field label="" name="extusr_fname" id="extusr_fname" mandatory="true" size="40" />
            </td>
        </tr>
		<tr>
            <td>
                <g:form_label>Enter User's Last Name</g:form_label>
            </td>
            <td>
            <g:ui_input_field label="" name="extusr_lname" id="extusr_lname" mandatory="true" size="40"/>
            </td>
        </tr>
		<tr>
            <td>
                <g:form_label>Enter User's Phone Number</g:form_label>
            </td>
            <td>
            <g:ui_input_field label="" name="extusr_phone" id="extusr_phone" mandatory="true" size="40"/>
            </td>
        </tr>
		<tr>
            <td>
                <g:form_label>RIW Number</g:form_label>
            </td>
            <td>
            <g:ui_input_field label="" name="extusr_riw" id="extusr_riw" mandatory="true" size="40"/>
            </td>
        </tr>
		<tr>
            <td>
                <g:form_label>Enter User's Company</g:form_label>
            </td>
            <td>            
            <g:ui_reference label="" name="extusr_company" id="extusr_company" table="core_company" mandatory="true"/>
            </td>
        </tr>
		<tr>
			<td colspan="2" style="text-align:right;padding-top:10px;">
				<button class="btn btn-default" onclick="processCancel()" style="margin-right:10px;">Cancel</button>
				<button class="btn btn-primary" onclick="okButton()">Ok</button>
			</td>
		</tr>
		
	</table>


</j:jelly>

 

 
Client Script:

 

//OK Button Script
function okButton(){
    var sysid = hidden_sys_id.value;
    var fname = extusr_fname.value;
	var lname = extusr_lname.value;
    var phone = extusr_phone.value;
    var company = extusr_company.value;
    //var manager = extusr_manager.value;
    var riw = extusr_riw.value;

	if (fname == ''){
		alert('First name is required');
		return false;
	}
	if (lname == ''){
		alert('last name is required');
		return false;
	}
	if (phone == ''){
		alert('Phone number is required');
		return false;
	}
	if (company == ''){
		alert('Company is required');
		return false;
	}
//time for some AJAX
var ga = new GlideAjax('newExtUser'); 
    ga.addParam('sysparm_name', 'createExtUser'); //ajax function
    ga.addParam('userfname',fname); //pass name into ajax
	ga.addParam('userlname',lname); //pass name into ajax
    ga.addParam('userphone',phone); //pass phone
    ga.addParam('usercompany',company); //pass company    
    ga.addParam('userriw',riw); //pass riw number
    ga.addParam('hidden_sys_id',sysid); //pass sysid into ajax
    
    ga.getXML(myCallBack); //process response
}

function myCallBack(response) { 
   //Dig out the 'answer' attribute
   var ajaxcomplete = response.responseXML.documentElement.getAttribute('answer'); 
    alert(ajaxcomplete); //alert the result to make sure all is well.
    GlideDialogWindow.get().destroy(); //Close the dialog window
    action.setRedirectURL(current);
    
}


//Cancel button script
function processCancel(){
		
	GlideDialogWindow.get().destroy();
	
}