How to cancel a flow on click of a UI action on a particular record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 06:44 AM
I have a requirement, where on click of a UI action ,I need to cancel the approval flow which gets triggered, but on click of the UI action the only a particular records approval flow should get cancelled,
for example :
I have submitted a ticket and sent for approval ,and if i click on the UI action present on the form ,should cancel the approval flow only for that particular record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 08:26 AM
Greetings!!
May i know what is the use of case , seems it is possible but with scripting , also need to see the impact of same.
A use case details help to guide you better.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 09:06 PM
HI @Sanket Pawar ,
I trust you are dong great.
Below is a sample script that you can use in your UI Action. This example assumes you are working with a Change Request record, but you can adapt it to other record types as needed:
// This script is to be used in a UI Action on the form of the record type (e.g., Change Request)
// Ensure the script only runs on the server side
if (g_user.hasRole('admin') && current.getTableName() == 'change_request') {
// Query the 'sysapproval_approver' table to find approvals related to the current record
var approvalGR = new GlideRecord('sysapproval_approver');
approvalGR.addQuery('sysapproval', current.sys_id);
approvalGR.addQuery('state', 'requested'); // Target only active ('requested') approvals
approvalGR.query();
while (approvalGR.next()) {
// Cancel each found approval
approvalGR.state = 'cancelled';
approvalGR.update();
}
// Optional: Add a message to inform the user that the approvals have been cancelled
gs.addInfoMessage('All approval requests for this record have been cancelled.');
}
action.setRedirectURL(current);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi