- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2025 01:28 AM
I have a UI action that spawns a UI Page, which in turn runs a Script Include in order to create an approval. The functionality works, but there's a problem - I can't figure out how to reload the form after sending the data. It must be reloaded in order to hide the button, thus preventing the user from creating multiple approvals (only one is permitted).
UI Action code (onclick: loadConfirmDialog(), client checkbox set to true):
var approvalDialog;
function loadConfirmDialog() {
var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
approvalDialog = new dialogClass("ask_for_approval_dialog", false, 648, 250);
approvalDialog.setPreference('sys_id', g_form.getUniqueValue());
approvalDialog.setTitle(new GwtMessage().getMessage("Ask for approval"));
approvalDialog.render();
}
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
//current.u_additional_approval = true;
//current.state = 3;
//current.u_hold_reason = 10;
current.update();
action.setRedirectURL(current);
}
UI Page client script:
function submitData() {
var reference = gel('approval_approver_ref').value;
var textArea = trim(gel('approval_reason').value);
var sysId = gel('sys_id').value;
if (!reference || !textArea)
return;
//console.log("MD: " + JSON.stringify(reference) + " " + JSON.stringify(textArea) + " " + sysId);
var ga = new GlideAjax('createApprovalFromUiAction');
ga.addParam('sysparm_name', 'createApprovalFromUiAction');
ga.addParam('sysparm_ritm', sysId);
ga.addParam('sysparm_approver', reference);
ga.addParam('sysparm_reason', textArea);
ga.getXML();
GlideDialogWindow.get().destroy();
//gsftSubmit(null, g_form.getFormElement(), "ask_for_approval_ui_page");
//action.setRedirect(current);
}
function cancelDialog() {
GlideDialogWindow.get().destroy();
}
I tried multiple things, and my findings are as follows:
1. The setRedirect() function doesn't run, so anything inside it does nothing. Is it possible to make the UI Action do something after closing the UI Page?
2. The commented out "gsftSubmit" function kind of does the trick, but it inconveniences the user. It kicks the user back to the previous page and displays the "Action not authorized" error.
3. I tried the "location.reload()" function in the UI Page, but it either did nothing, or reloaded the page BEFORE it sent any data.
How can I make all of that work together?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2025 03:43 AM
it worked for me with this simple UI page, It reloaded the form
give this for dialog buttons and don't give extra attributes
<g:dialog_buttons_ok_cancel cancel="return cancelDialog();" ok="return submitData();"/>
My UI Page and Output:
In your client script set return true and see if it works
function submitData() {
var reference = gel('approval_approver_ref').value;
var textArea = trim(gel('approval_reason').value);
var sysId = gel('sys_id').value;
if (!reference || !textArea)
return;
//console.log("MD: " + JSON.stringify(reference) + " " + JSON.stringify(textArea) + " " + sysId);
var ga = new GlideAjax('createApprovalFromUiAction');
ga.addParam('sysparm_name', 'createApprovalFromUiAction');
ga.addParam('sysparm_ritm', sysId);
ga.addParam('sysparm_approver', reference);
ga.addParam('sysparm_reason', textArea);
ga.getXML();
GlideDialogWindow.get().destroy();
return true;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2025 04:20 AM
Alright, I added this line
action.setRedirect(current);
just before these lines:
GlideDialogWindow.get().destroy();
//return true;
The commented out line doesn't seem to do anything. However, seems like it finally works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2025 01:58 AM
Also I have that condition - it works AS SOON AS the form reloads. That's why I want it to reload after sending data!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2025 02:07 AM
to use processing script you need to use <g:ui_form> in your UI page html
if that form is submitted then only processing script is executed
please share your complete UI page HTML here
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2025 02:08 AM
<?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_sys_id" expression="RP.getWindowProperties().get('sys_id')" />
<g:ui_form>
<input type="hidden" name="sys_id" id="sys_id" value="${jvar_sys_id}" />
<div class="row form-group">
<div class="col-md-2 text-right">
<label for="approval_approver">Approver<span style="color:red;font-size:x-large;">*</span></label>
</div>
<div class="col-md-10">
<g:ui_reference
name="approval_approver_ref"
id="approval_approver"
label="Approver"
query="u_technical_user=false^active=true^ORDERBYname"
completer="AJAXTableCompleter"
table="sys_user"
mandatory="true"
/>
</div>
</div>
<div class="row form-group">
<div class="col-md-2 text-right">
<label for="approval_reason">Reason for Approval <span style="color:red;font-size:x-large;">*</span></label>
</div>
<div class="col-md-10">
<textarea class="form-control" name="approval_reason" id="approval_reason" rows="10"></textarea>
</div>
</div>
<div class="fixed-bottom">
<g:dialog_buttons_ok_cancel
ok_id="ok_btn"
ok="return submitData()"
ok_type="button"
ok_style_class="btn btn-primary"
cancel_type="button"
cancel_id="cancel_btn"
cancel_style_class="btn btn-default"
cancel="return cancelDialog()"
/>
</div>
</g:ui_form>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2025 02:23 AM
did you add logs and see if processing script ran?
I could see you already using <g:ui_form> so processing script should work
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2025 02:28 AM
I added gs.info("MD: Processing script ran"); and seems like it doesn't run. It's not in the logs.