Force end the workflow

Feddy
Kilo Sage

Hi Team , 

We have two catalog item as below 

1. to add access when the start time is met and to revoke access when the end time is met
2  User can submit another request to revoke the access well.

I need to move the first catalog item workflow end activity if the user submits the second catalog item request.
I am able to update the workflow context and able to cancel the workflow as well but the workflow is not moving to end activity.

Any inputs on this would be much appreciated !

1 ACCEPTED SOLUTION

Hi,

try to cancel the workflow using script then

var workflow = new Workflow();

workflow.cancel(grReqItem); 

Regards
Ankur

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

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So why not close the 1st RITM and REQ when same user requests 2nd catalog item? If you close then workflow will reach end activity.

This can be done at the beginning of the 2nd catalog item workflow

Regards
Ankur

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

var grReqItem = new GlideRecord('sc_req_item');
    grReqItem.addQuery('sys_id', <RITM sys_id>);
    grReqItem.query();
    if (grReqItem.next()) {
        grReqItem.work_notes = "Your ReadOnly Admin access has been revoked as the <user> submitted revoke access request";
        grReqItem.active = false;
        grReqItem.state = 3;
        grReqItem.stage = 'complete';
        grReqItem.update();
    }

 

we have above script in place but still not working

Hi,

where are you writing this script and when it's triggering?

Regards
Ankur

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

@Ankur Bawiskar 
It is in the second catalog item workflow.
When user submits the second catalog item , in the workflow run script I added this script . I am able to close the first catalog item request and request item but the stage of that is not getting updated . 

We are giving users a ReadOnly admin role as part of the first catalog item.
Their group mates can submit the second catalog item so that the access will be revoked also the first RITM should should moved to closed complete.