Popup for cancel confirmation not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
I am trying to create a UI Action with name 'Cancel RITM', which will be asking for reason for cancellation, and cancel /Ok button. Once Ok is clicked, it will verify if there is some value or not, if no value it will give an info message and won't allow to proceed further, If value is there it will allow to make the RITM closed incomplete( value =4) and update the work notes with "Cancelled: " + cancel comments.
Below is the UI action and Ui page am trying, but it is not working as expected, am not getting any error.
Just the OK button is not validating anything and updating anything. It is redirecting to "ui_page_process" page with UI action sys id.
Ui action
Ui page
HTML
Client script
Processing script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
There are a few issues here — both in the code and likely in the UI Action configuration. Let me walk through them.
UI Action Configuration Issues
For a client-side UI Action to save and work properly, you need to ensure:
- The Client checkbox is checked on the UI Action form.
- The Onclick field contains the function call:
promptForReason() - The Script field contains only the function definition.
If the "Client" checkbox isn't checked and you're writing client-side code (using g_form, GlideAjax, etc.), ServiceNow will reject it or throw errors on save because it tries to validate it as server-side script.
Script Include Issue
Your Script Include is missing the type property, which can cause problems:
var RecordUpdateHandler = Class.create();
RecordUpdateHandler.prototype = Object.extendsObject(AbstractAjaxProcessor, {
updateReason: function() {
var gr = new GlideRecord('incident');
if (gr.get(this.getParameter('sysparm_id'))) {
gr.work_notes = "Reason: " + this.getParameter('sysparm_reason');
gr.update();
return 'success';
}
return 'error';
},
type: 'RecordUpdateHandler'
});
Also make sure the Client callable checkbox is checked on the Script Include, otherwise GlideAjax won't be able to invoke it.
UI Action Script Refinement
The prompt() browser dialog can be unreliable across ServiceNow UI versions (especially in UI16/Next Experience). A safer approach using GlideModal or a simple dialog:
function promptForReason() {
var dialog = new GlideDialogWindow('glide_ask_standard');
dialog.setTitle('Enter Reason');
dialog.setPreference('sysparm_cancel_text', 'Cancel');
dialog.setPreference('sysparm_ok_text', 'Submit');
dialog.setPreference('sysparm_message', 'Please enter the reason for this update:');
dialog.setPreference('sysparm_type', 'textarea');
dialog.setPreference('sysparm_ok_callback', function(win) {
var reason = win.document.getElementById('glide_ask_standard_value').value;
if (reason) {
var ga = new GlideAjax('RecordUpdateHandler');
ga.addParam('sysparm_name', 'updateReason');
ga.addParam('sysparm_id', g_form.getUniqueValue());
ga.addParam('sysparm_reason', reason);
ga.getXMLAnswer(function(response) {
if (response === 'success') {
g_form.addInfoMessage('Updated successfully.');
g_form.refresh();
}
});
}
});
dialog.render();
}
Quick checklist to get it saving:
- Check the Client checkbox on the UI Action.
- Put
promptForReason()in the Onclick field. - Put the function definition in the Script field.
- Add
type: 'RecordUpdateHandler'to the Script Include. - Check Client callable on the Script Include.
Try saving again after making these changes — the most common culprit is the missing "Client" checkbox, which causes ServiceNow to parse client-side code as server-side and fail validation.
