UI Page Button Redirect to Current Form

Thomas_J_C
Mega Expert

I created a UI Page called from a UI Action to display related records from a parent record. The data is fine however the processing script for my UI Page is not redirecting to the current form after I submit the UI Page. 

The client script section is working great, I just need the same functionality as a action.setRedirectURL(current) in a normal UI Action when I click a button. Essentially, I would like a "Save" button functionality.  

The code is copied below:

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_id" expression="RP.getWindowProperties().sys_id">
var rec = new GlideRecord('x_270032_siarra_siarra_task');
rec.query();
rec;
</g:evaluate>

<g:evaluate object="true" var="jvar_statements">
var fire = new GlideRecord('x_270032_siarra_siarra_firewall');
fire.addQuery('firewall_task', '${jvar_id}');
fire.query();
fire;
</g:evaluate>
<g:ui_form>
<div class="panel panel-primary">
<div class="panel-heading">Related Firewall Records</div>
<div class="panel-body">
<table class="table table-bordered">
<thead>
<tr bgcolor='#b3c6ff' align='center'>
<th style='text-align:center;'><strong>Record</strong></th>
<th style='text-align:center;'>Protocol</th>
<th style='text-align:center;'>Destination IP</th>
<th style='text-align:center;'>Service</th>
<th style='text-align:center;'>Ports</th>
<th style='text-align:center;'>Source IP</th>
<th style='text-align:center;'>Direction</th>
<th style='text-align:center;'>Link</th>
</tr>
</thead>
<j:while test="${jvar_statements.next()}">
<g:evaluate>
var implement;
if (${jvar_statements.getValue('implemented')} == 0) {
implement = 'False';
}
else if (${jvar_statements.getValue('implemented')} == 1) {
implement = 'True';
}
</g:evaluate>
<tbody>
<tr>
<td>${jvar_statements.getValue('number')}</td>
<td>${jvar_statements.getValue('protocol')}</td>
<td>${jvar_statements.getValue('destination_ip')}</td>
<td>${jvar_statements.getValue('service')}</td>
<td>${jvar_statements.getValue('ports')}</td>
<td>${jvar_statements.getValue('source_ip')}</td>
<td>${jvar_statements.getValue('direction')}</td>
<td><button type="button" class="btn btn-primary btn-block" style='text-align:center; position:relative;'><a href="https://dev49612.service-now.com/x_270032_siarra_siarra_firewall.do?sys_id=${jvar_statements.getValue('sys_id')}" style="color:white;">Link</a></button></td>
</tr>
</tbody>
</j:while>
</table>
<footer class="modal-footer flex" style="width:25%;float:right">
<g:dialog_buttons_ok_cancel ok="return confirmRules()" ok_type="submit" ok_title="Confirm Rules" ok_text="Confirm" cancel_text="Close" cancel_type="button" cancel_title="Close"/>
</footer>
</div>
</div>
</g:ui_form>
</j:jelly>

 

CLIENT SCRIPT:

//mark all related records as implemented and redirect user
function confirmRules() {


var firewallId = g_form.getUniqueValue();
var firewallNum = g_form.getValue('number');
var sys = g_form.getValue('sys_id');

var ajaxCall = new GlideAjax('siarraAjax');
ajaxCall.addParam('sysparm_name', 'confirmRules');
ajaxCall.addParam('sysparm_firewallId', firewallId);
ajaxCall.addParam('sysparm_number', firewallNum);
ajaxCall.addParam('sysparm_sysid', sys);

GlideDialogWindow.get().destroy();


ajaxCall.getXMLAnswer(function(answer) {
if(answer == 'true') {

}
});
}

 

PROCESSING SCRIPT: (NOT WORKING)

var urlOnStack = GlideSession.get().getStack().bottom();
response.sendRedirect(urlOnStack);

1 ACCEPTED SOLUTION

Hi Thomas,

Is the current code not redirecting as per your requirement?

you can use the html hidden element value to form the url for redirection

Why you want to query again in processing script?

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

hello sir,

What is the other way to redirect to current form from uipage client script.

Sagar Manocha
Tera Contributor

Your processing script is not working because you have enclosed your ok_cancel button inside <g:ui_form> tag. Once you do it, your processing script will run smoothly. Make these changes in your html code.

 <g:ui_form>

<g:dialog_buttons_ok_cancel ok="return confirmRules()" ok_type="submit" ok_title="Confirm Rules" ok_text="Confirm" cancel_text="Close" cancel_type="button" cancel_title="Close"/>

</g:ui_form>

Thanks

Sagar Manocha