Popup on change request form when user clicks on a ui action and state is in draft or new
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 12:57 AM
Hi Community,
I have a custom field created on the change form which is a checkbox field. Until user check that checkbox and there are no related items in the change requests related list, i want to show an alert. Also, when user clicks on request approval ui action and state is new or draft all the time then i want to show same alert. Any one condition satisfies then want to show this alert i.e. either that checkbox is checked or there are no related items in the related list then show alert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 01:50 AM
HI @Poorva Bhawsar ,
I trust you are doing great.
Please find the updated code which you can reference .
function onLoad() {
// Add the alert functionality when the form is loaded
showAlert();
}
function showAlert() {
var nonProdTestNotRequired = g_form.getValue('u_non_production_test_not_required');
var state = g_form.getValue('state');
// Check if the checkbox is unchecked
if (nonProdTestNotRequired == 'false' || nonProdTestNotRequired == '') {
// Check if there are no related items in the "Change Requests" related list
var gr = new GlideRecord('change_request');
gr.addQuery('parent', g_form.getUniqueValue());
gr.query();
if (!gr.next()) {
gs.addInfoMessage('A valid non-production change must be linked in the "Change Requests" related list or justification for no non-production test evidence provided via the "Non Production Test Not Required" checkbox.');
}
}
// Check if the "Request Approval" UI action is clicked and the state is "New" or "Draft"
if (state == '-5' || state == '1') {
gs.addInfoMessage('A valid non-production change must be linked in the "Change Requests" related list or justification for no non-production test evidence provided via the "Non Production Test Not Required" checkbox.');
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 12:54 AM
Is it on ui action? Because we cant use gs in client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 01:06 AM
This is not working on ui action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 01:54 AM
where have you written the script? what debugging have you done so far?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader