Workflow().broadcastEventToCurrentsContexts(gr, 'update', null) is not starting the Workflow

Gowtham Kodali
Tera Contributor

I have a custom choice in the sc_task if that choice is selected the workflow is stopping if the task state is change to closed cancelled(custom choice)

I have created a BR on sc_task to start the work flow again

i have used 

Workflow().broadcastEventToCurrentsContexts(gr, 'update', null) 

 

to start the workflow again but the workflow is not starting again any ideas how to stat the workflow again

 

Thank you,

Gowtham

1 ACCEPTED SOLUTION

@Gowtham Kodali 

Please use this workaround and this should work fine.

Business rul

Table: sc_task
When: after update
Condition: State changes to Close Cancelled

(function executeRule(current, previous /*null when async*/) {

var wf = new Workflow();
var ri = new GlideRecord("sc_req_item");
if (ri.get(current.request_item)) {
wf.runFlows(ri, 'update');

}
})(current, previous);

Reference:

activity.result = '10' not working for custom state values

Regards
Ankur

 

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

View solution in original post

25 REPLIES 25

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Gowtham,

your workflow is on which table?

since your BR is on sc_task

if you are waiting for update on same table as that of workflow then no need of the above script

please share complete script and scenario

Regards
Ankur

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

My work flow is on the RITM .

Scenario is 

 

I have a workflow on RITM where a task is created if the Request is approved,If the task state is changed to closed cancelled then the work flow should be finshed, Now even the task is being closed cancelled The work flow is still running so I created a Business Rule on the sc_task table to start the workflow after the Task state is changed to Closed Cancelled. but still  when the task state is changed to Closed cancelled the Workflow is still Executing ,instead of stopping 

 

Script I used is 

 

var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id',current.request_item);
gr.query();
if (gr.next()) {
 new Workflow().broadcastEventToCurrentsContexts(gr, 'update', null);
}

Hi,

Did you use any wait for condition in your RITM workflow?

please share workflow image?

Regards
Ankur

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

I dont have any Wait condition in RITM workflow

 

find_real_file.png