cancel workflow from flow or using Business rule

Saras Moorthi
Tera Contributor

i'm not sure how to create run script activity in flow , need some guidance on this

 

alternatively, I tried with after Business rule with script as below, it's just setting flow context to cancel and i still can view the workflow from show workflow option. How do i remove the workflow completely?

 

 if ((current.stage == 'Request Cancelled') && current.context
          && !current.context.nil()) {
      var w = new Workflow();
      var now_GR = new GlideRecord('wf_context');
     
      if (now_GR.get(current.context))
          w.cancelContext(now_GR);
      }
1 ACCEPTED SOLUTION

@Saras Moorthi 

that Related link is not visible to all

what's the point in this requirement if the workflow is already cancelled via your script

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

View solution in original post

8 REPLIES 8

@Saras Moorthi 

that Related link is not visible to all

what's the point in this requirement if the workflow is already cancelled via your script

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

Hi @Ankur Bawiskar 

 

that show workflow link is still visible to end users. my br just setting workflow context to cancelled. is there a way to remove that workflow completely?

 

@Saras Moorthi 

you can update the UI action condition but it's an OOB UI action

Also why end users are seeing that button?

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

Community Alums
Not applicable

HI @Saras Moorthi 

Can we do like this, I have used a Before Insert BR on my custom table and running this script....

 

var rec = new GlideRecord('u_customTable');

 

rec.addQuery('number', current.number);

rec.query();

if (rec.next()) {

var workflow = new global.Workflow();

workflow.cancel(rec);

gs.info("Existing Recors is " + rec.sys_id);

}