Cancel UI action on Catalog task

Shruti Chelimel
Tera Expert

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.

8 REPLIES 8

@Shruti Chelimel 

check this link

Debugging Business Rules 

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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Shruti Chelimel 

 

Why do you need to cancel? You can use the closed skip if required which is OOTB and you can define SLA etc on the same. A new UI Action will increase technical debt and overhead in future releases. 

*************************************************************************************************************
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]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@Shruti Chelimel 

are you having approvals on catalog task or RITM?

try this in the UI action for approval on both levels

The UI action should be server side

cancelTask();

function cancelTask() {

    // Set the state to 'Close cancelled'
    current.state = '4';
    current.update();

    // Cancel all approvals
    var approvalRecord = new GlideRecord('sysapproval_approver');
    approvalRecord.addQuery('document_id', current.sys_id).addOrCondition('document_id', current.request_item);
    approvalRecord.addEncodedQuery('stateINrequested');
    approvalRecord.query();
    while (approvalRecord.next()) {
        approvalRecord.state = 'cancelled';
        approvalRecord.update();
    }

    var slaRec = new GlideRecord('task_sla');
    slaRec.addQuery('task', current.sys_id);
    slaRec.query();
    while (slaRec.next()) {
        slaRec.state = 'cancelled';
        slaRec.active = false;
        slaRec.update();
    }

    // Redirect to the task list
    action.setRedirectURL(current);
}

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

@Shruti Chelimel 

Hope you are doing good.

Did my reply answer your question?

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