- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2019 01:18 PM
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);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 07:39 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2019 10:11 PM
Hi,
for processing script to trigger create a new html hidden element; and check in processing script
<g:evaluate var="jvar_id" expression="RP.getWindowProperties().sys_id">
var rec = new GlideRecord('x_270032_siarra_siarra_task');
rec.query();
rec;
</g:evaluate>
<input type="hidden" id="hidden" value="jvar_id"/>
processing script:
if(hidden){
var urlOnStack = GlideSession.get().getStack().bottom();
response.sendRedirect(urlOnStack);
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 06:30 AM
Creating the hidden input element definitely helped me out. In the processing script, how would I access the current record the dialog is current displayed over? Would I use a standard GlideRecord Query?
Example:
var gr = new GlideRecord('tableName');
gr.get(current.sys_id);
gr.query();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 07:39 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2020 02:53 PM
Hi
I am looking for a similar functionality. My UI page is redirecting after I clilck OK on the Transfer Case page .
Below is the code , please suggest what changes I need to make in my Processing Script .
(function(_this) {
var urlOnStack = gs.getSession().getUrlOnStack();
var originalTask = new GlideRecord(task_table_name);
if (!originalTask.get(task_sys_id)) {
gs.addErrorMessage(gs.getMessage("Could not find original case"));
return;
}
// Create new Incident from Case
var inc = new GlideRecord('incident');
inc.initialize();
// HR Case fields that will carry over to the IT Incident
inc.short_description = originalTask.short_description;
inc.category = 'Inquiry / Help';
inc.subcategory = 'Other';
inc.impact = '4';
inc.urgency = '3';
inc.description = originalTask.description;
inc.assignment_group = assignment_group;
var worknote = gs.getMessage("Transferred from HR case {0}", [originalTask.number]);
worknote += '\n\n Work History from HR Case \n\n';
worknote += originalTask.work_notes.getJournalEntry(-1);
inc.work_notes = worknote;
inc.contact_type = 'transfer_hr';
inc.u_email = originalTask.opened_for.email;
inc.u_email = originalTask.opened_for.phone;
inc.parent = originalTask.sys_id; //References HR Case from IT Incident form. Update with your custom Incident field or remove this line.
inc.caller_id = originalTask.opened_for;
inc.insert();
GlideSysAttachment.copy(originalTask.sys_class_name,originalTask.sys_id,'incident',inc.sys_id);
var inc_num = inc.number;
var hrcomments = gs.getMessage("This case has been transfered to IT. New incident number is {0}", [inc_num]);
var incLink = '[code]<a target="_blank" href="./incident.do?sys_id='+inc.sys_id+'">'+inc.number+'</a>[/code]';
var hrnotes = gs.getMessage(' Incident Link : {0}', [incLink]);
if(selected_decision == '1')
{
hrcomments += '\n\n'+comments;
hrnotes += '\n\n'+worknotes;
originalTask.state = '20'; // Awaiting Acceptance
}
originalTask.comments = hrcomments;
originalTask.work_notes= hrnotes;
originalTask.update();
response.sendRedirect(urlOnStack);
})(this);