The CreatorCon Call for Content is officially open! Get started here.

How do I add a pop up warning message if updating the state field to Cancelled with open child tasks

matthew_hughes
Kilo Sage

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:

  1. How do I add the warning message if the user changes the incident to Cancelled?
  2. How do I change the the state of the related incident tasks to Cancelled.
5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@matthew_hughes 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Do you have an example script that could be used for the confirmation box?

@matthew_hughes 

it's normal confirm javascript pop-up

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Riya Verma
Kilo Sage

Hi @matthew_hughes ,

 

Hope you are doing great.

 

  1. 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);
​

 

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma