Confirm Dialog box in Servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi all,
I have one requirement.
I have one field called group on the catalog form.
We have one MRVS, it contains filed group. Group field will be populated with value based on the Group field on the catalog form.
Requirement -
Select group on the form, add values in MRVS. Then if we try to change the group field , it has to show one Confirm Message("If you change the group, it will clear the all rows in MRVS").
1. If user click "Ok", MRVS rows has to be cleared and Group has to show with new Group Value. (Working as expected now)
2. If user clicks on "Cancel", Group has to show the Old Group only.
Currently #2 is not working as expected.
Please let me know if you guys have any thoughts on this. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
assignment_group is name of the MRVS.
u_group is the field on the catalog form. So I have written Client Script on Catalog level.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
31m ago
try this
1) create hidden string variable to hold previous value i.e. u_prev_group
2) then use this script, onchange of that variable
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isTemplate) {
return;
}
if (isLoading) {
g_form.setValue('u_prev_group', g_form.getValue('u_group') || '');
window.groupChangeInProgress = false;
return;
}
if (window.groupChangeInProgress) {
window.groupChangeInProgress = false;
return;
}
newValue = (newValue || '').toString();
var previousGroup = (g_form.getValue('u_prev_group') || '').toString();
var mrvsValue = g_form.getValue('assignment_group');
var hasRows = mrvsValue && mrvsValue !== '[]';
if (newValue === previousGroup) {
return;
}
if (!hasRows) {
g_form.setValue('u_prev_group', newValue);
return;
}
if (confirm('If you change the group, it will clear all rows in MRVS.')) {
g_form.clearValue('assignment_group');
g_form.setValue('u_prev_group', newValue);
} else {
window.groupChangeInProgress = true;
g_form.setValue('u_group', previousGroup);
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
43m ago
Hi @KS86
Can you try with this:
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
18m ago
Hi @KS86
For this requirement, g_form.setValue('u_group', oldValue) alone usually does not work properly in a catalog onChange, because:
- setValue() triggers the onChange again
- The field has already changed in UI
- For catalog variables, reverting immediately sometimes fails unless you use a flag + small timeou
Try this script
If this response addressed your question, please mark it as Helpful and accept it as the solution.