Create 'Cancel' Button to Cancel Request for Change Request

UdhayakumarS559
Tera Contributor

Hi all ,

I would like to add a 'Cancel' button to the Change Request (change_request) form.

UdhayakumarS559_0-1751297807841.png

 

📌 Requirement:
At the top-right corner, there should be an option to press 'Cancel', which should:

  • Cancel the current change request (e.g., set the state to Canceled)

  • Exit the form

  • Undo the attempt to submit the request

As shown in the attached screenshot, I’d like this button to behave similarly to the 'Delete' or 'Update' buttons, but specifically to cancel the request gracefully.

Can anyone suggest the best way to implement this — using a UI Action or another approach?
If using a UI Action, please provide the correct steps to create it, the script code, and the UI Action order (as the order affects whether the button is displayed properly).

Thank you!

6 REPLIES 6

brianrichards
Tera Guru

This appears rather straightforward and similar to the UI Action on the Request table. 

Create a UI action

Select Show Insert and Show Update

In the Script field use this:

current.state = 4;
current.update();
 
There are more best practices to be identified about the 'right' way to handle cancelling Change Requests, but technically I think this should do it. 

I have created a UI Action for Cancel in the Change form. This is my UI Action—check if there is any mistake here and let me know.
UdhayakumarS559_0-1751362932405.png

 

This is my script code:
 

var changeConfirmCancelDialog;
function cancelChangeRequest() {
g_form.setValue("state", "4");
}

if (typeof window == 'undefined') {
runCancel();
}

function runCancel() {
current.update();
action.setRedirectURL(current.getTableName() + '_list.do');
}

I have no idea about this line: var changeConfirmCancelDialog;. I know this is for the Change confirmation popup, but I don’t know exactly how it works. Please explain.

Also, how does this condition work: new ChangeFormUI(current).isCancelAvailable()? Please explain how this condition works.

 

Thanks

@UdhayakumarS559 

ChangeFormUI script include extends ChangeFormUISNC script include.

It has isCancelAvailable() function which returns true/false based on some check

Since you are using Change State Model transition, it will check if it's allowed to move to Cancel state based on current state.

it calls another script include "ChangeRequest"

AnkurBawiskar_0-1751363784339.png

 

AnkurBawiskar_1-1751363879361.png

 

I hope this much details should be sufficient for you to debug and understand further

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

AndersBGS
Tera Patron
Tera Patron

Hi @UdhayakumarS559 ,

 

There is only one straight forward method - create a UI action as you have already stated. 

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/