Cancel UI action on Catalog task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2024 05:20 AM
I need a cancel button on catalog task form. When Cancel UI action is clicked, the sc_task state should be changes to 'Close cancelled' and all its approval along with SLA's should also be cancelled and made inactive.
Please suggest an possible way to achieve this requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2024 02:00 AM - edited ‎12-27-2024 02:02 AM
Hi @Shruti Chelimel ,
You can use below script in UI Action.
Create New UI action called "Cancel".
current.state = '4'; // replace with Closed Cancelled value
current.update();
// Cancel associated approvals
var approvalGR = new GlideRecord('sysapproval_approver');
approvalGR.addEncodedQuery('document_id='+current.sys_id+'^stateNOT INapproved,rejected,cancelled');
approvalGR.query();
while (approvalGR.next()) {
approvalGR.state = 'cancelled'; // Change to "Cancelled"
approvalGR.update();
}
// Cancel SLAs
var slaGR = new GlideRecord('task_sla');
slaGR.addQuery('task', current.sys_id);
slaGR.addQuery('stage', '!=', 'cancelled');
slaGR.query();
while (slaGR.next()) {
slaGR.stage = 'cancelled'; // Mark SLA as cancelled
slaGR.active = false; // Set SLA to inactive
slaGR.update();
}
// Redirect the user back to the list view or refresh the form
action.setRedirectURL(current.getTableName() + "_list.do");
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2024 02:46 AM
Hi @Runjay Patel ,
I wrote the code in same way, but the state is changing to Closed Complete instead of Closed Cancelled. Some other script is changing the state to Closed Complete. I am unable to figure out exactly how the state is changing to Closed Complete instead of Closed Cancelled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2024 04:48 AM
Hi @Shruti Chelimel ,
Do you have close cancelled state as it wont come with OOB. Make sure you are putting the right value.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2024 05:15 AM
there would be some other script which is moving the state again
Did you debug business rules and see?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader