UI Page called through workspace client script doesn't return value back to UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 11:34 AM
Hi Team,
I have an UI Action called 'Close Confirm' which is working fine in the instance side.
I'm using UI Page to display a confirm box with two buttons 'Continue' and 'Cancel'
When the user clicks on Continue, the case should be closed. no changes should be done to the form when the user clicks on Cancel.
UI Action Workspace Client Script:
function onClick(g_form) {
var c1 = g_form.getValue('number');
var c2 = g_form.getDisplayValue('assignment_group');
var t1 = 'Close the Case';
var errMsg = buildErrorMessage();
g_modal.showFrame({
title: t1,
url: 'confirm_close?sysparm_case_number=' + c1 + '&sysparm_case_group=' + c2 + '&sysparm_error_message=' + errMsg + '&sysparm_type=interaction&sysparm_workspace=' + true,
size: 'xl',
// autoCloseOn: 'URL_CHANGED',
callback: function(ret, data) {
if(ret) {
g_form.submit('close_confirm');
}
}
});
}
function buildErrorMessage() {
var errorMessage = '';
if (!g_form.getValue('resolution_code')) {
errorMessage = 'Resolution Code';
}
return errorMessage;
}
UI Page 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:ui_form onsubmit="return ok()">
<table border="0" width="100%">
<tr>
<td />
<p style="text-align:left; font-size: larger;">To close the case, click on  <b>Continue</b>, Once case is closed it can not be reopened</p>
<p style="text-align:left"><b>Case Number</b>: ${JS:sysparm_case_number}</p>
<p style="text-align:left"><b>Assignment Group</b>: ${JS:sysparm_case_group}</p>
<div style="text-align:left;">To close the window instead, click  <b>Cancel</b>, then navigate BACK</div>
<td />
</tr>
<g:evaluate jelly="true">
var title = (jelly.RP.getWindowProperties().get('title') || '') + '';
title = new GlideStringUtil().unEscapeHTML(title);
var warning = (jelly.RP.getWindowProperties().get('warning') || '') + '';
warning = new GlideStringUtil().unEscapeHTML(warning);
</g:evaluate>
<j:if test="${warning == 'true'}">
<tr>
<td>
<div style="margin-top: 6px; color: tomato; font-size:larger;text-align:center;">
<b>Warning</b>
</div>
</td>
</tr>
</j:if>
<tr>
<td nowrap="true">
<g:no_escape>${title}</g:no_escape>
</td>
</tr>
<tr>
<td />
<td />
</tr>
<tr>
<td style="padding: 10px;" colspan="2" align="right">
<g:dialog_buttons_ok_cancel ok="return ok()" ok_type="button" ok_text="${'Continue'}" cancel="return cancel()" cancel_type="button" cancel_text="${'Cancel'}" />
</td>
</tr>
</table>
</g:ui_form>
<script>
document.getElementById("ok_button").focus();
</script>
</j:jelly>
UI Page Client Script:
function ok() {
var config = {
workspace: '${JS_STRING:RP.getParameterValue("sysparm_workspace")}' == 'true'
};
if (!config.workspace) {
var gm = GlideModal.get();
var errorMessage = '${JS:sysparm_error_message}';
if (errorMessage) {
g_form.addErrorMessage('Please fill these mandatory fields to close the case: ' + errorMessage);
gm.destroy();
return false;
}
gsftSubmit(null, g_form.getFormElement(), '10835e2d83f3921039f9bf10feaad30d');
} else {
g_form.submit('close_confirm');
return true;
}
}
function cancel() {
var config = {
workspace: '${JS_STRING:RP.getParameterValue("sysparm_workspace")}' == 'true'
};
if (!config.workspace) {
GlideModal.get().destroy();
return false;
} else {
window.location.href = window.location.href + '&sysparm_next_pg=true';
return false;
}
}
When the user clicks on Cancel, the dialogbox is getting closed, but when the user clicks on Continue, nothing is happening. It is still displaying the dialogbox.
How to send the user response from UI Page client script to UI Action workspace client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 07:56 PM
are you sure the callback method was called?
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
‎02-26-2025 10:51 PM
The callback method was called.
callback: function(ret, data) {
console.log('statement1');
if(ret) {
console.log('statement2');
}
}
in the console, I can see statement1 but statement2 is not printed.
From the callback function,
value of ret is false
value of data is undefined
even when I'm trying to set return true in UI page client script, the callback function in UI Action is getting false for variable ret
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2025 10:57 PM
can you try this?
callback: function(ret, data) {
if(data.actionType == "ok") {
g_form.submit('close_confirm');
//
g_form.save();
}
}
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