How do I add a pop up warning message if updating the state field to Cancelled with open child tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-26-2023 02:10 AM
In the incident table, if a user sets an active incident to the state of Cancelled, but the incident has open incident tasks, I'm wanting to add a warning message that If you choose to cancel this incident then all non-closed tasks will be updated as Cancelled. The warning message should have a confirm and cancel buttons. There are two things that I'm wanting to know:
- How do I add the warning message if the user changes the incident to Cancelled?
- How do I change the the state of the related incident tasks to Cancelled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-26-2023 02:18 AM
you can use onSubmit client script and use confirm box to get the confirmation
If user agrees then allow the form to get submitted
To change the state of related incident tasks to cancel you can use after update BR on incident table and set the state
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
ā06-26-2023 02:45 AM
Do you have an example script that could be used for the confirmation box?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-26-2023 03:06 AM
it's normal confirm javascript pop-up
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-26-2023 03:06 AM
Hi @matthew_hughes ,
Hope you are doing great.
- How do I add the warning message if the user changes the incident to Cancelled? : You can use on submit client script to add warning message.
function onSubmit() {
if (g_form.getValue('state') == 'Cancelled' ) {
if (confirm('If you choose to cancel this incident, all non-closed tasks will be updated as Cancelled. Do you want to proceed?')) {
return true; // Allow form submission
} else {
return false; // Cancel form submission
}
}
return true; // No warning required, allow form submission
}
ā
2. How do I change the the state of the related incident tasks to Cancelled. :
To update the state of related incident tasks to "Cancelled," you can use a business rule.
(function executeRule(current, previous) {
if (current.state == 'Cancelled') {
var incidentTasks = new GlideRecord('incident_task');
incidentTasks.addQuery('incident', current.sys_id);
incidentTasks.addQuery('state', '!=', 'Closed');
incidentTasks.query();
while (incidentTasks.next()) {
incidentTasks.state = 'Cancelled';
incidentTasks.update();
}
}
})(current, previous);
ā
Regards,
Riya Verma