How to implement OOB cancel UI action for Incident.

Sangeetha8
Tera Contributor

Hi All,

 

I want to replicate the cancel popup button in problem to incident.

I don't know how to edit the OOB cancel UI action. IN OOB UI action there is script include which is not editable.

so without using the OOB UI action how to achieve this

In the below image the state is closed when I click cancel button, but I need to set the state as cancelled when I click the cancel button.

 

Sangeetha8_0-1732269280047.png

 

Anyone can please advice.

Thanks,

 

1 REPLY 1

merry678gar
Tera Contributor

Hello,

To achieve the desired functionality of changing the state to "Cancelled" instead of "Closed" when clicking the cancel button in ServiceNow, you can create a custom solution without modifying the Out-of-Box (OOB) UI Action.

Here’s how you can proceed:

1. Create a New UI Action
Navigate to System Definition > UI Actions.
Click New to create a new UI Action.
Fill in the fields:
Name: Cancel and Set State as Cancelled
Table: Select the table (e.g., Incident).
Active: Check this box to activate the action.
Show on form: Check this box if you want it to appear on the form.
Script Section:
Use the following script to set the state to "Cancelled":

javascript
Copy code
// Check for necessary permissions or conditions
if (current.state != 'Cancelled') {
// Change the state to Cancelled
current.state = 'Cancelled';

// Optionally add comments or updates to the record
current.work_notes = 'Cancelled by user via custom UI action.';

// Update the record
current.update();

// Redirect or refresh the form
action.setRedirectURL(current);
} else {
gs.addInfoMessage('The record is already cancelled.');
}    unitedhealthcare login
Best Regards
merry867