Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Workflow Wait condition script

Sam Ogden
Tera Guru

Hi All,

I've created a new workflow for a catalog Item.   The Catalog item has 5 checkbox variables.   Each checkbox decides if a task is generated.   We have scenarios however that once the ITEM has been submitted we might need to manually create further tasks.

I've created a wait condition script to check all tasks are closed before moving to a run script to close the ITEM.

For example If 2 checkboxes on the catalog item were true, 2 tasks get generated.   We then manually create a 3rd task.

If the manually created task is closed before either of the workflow generated tasks the workflow works fine.

If the manually created task is the last task to be closed the workflow remains stuck at the wait condition.   If I then go into the workflow context and 'nudge' the workflow, the wait condition runs and the workflow completes.


Is there a way to amend the workflow or some other means to get the workflow to complete without having to manually nudge the workflow?

Below is the workflow and the wait condition script:

find_real_file.png

find_real_file.png

Any help is greatly appreciated

Thanks

Sam

1 ACCEPTED SOLUTION

Hi Andrii,



Thanks for all your help on this.   I have managed to get this working following trawling through many articles on here.   one had a link to the following:


Condition Activities - ServiceNow Wiki


section 4.4 example script got this working.



Thanks



Sam


View solution in original post

12 REPLIES 12

Andrii
Kilo Guru

Wait condition always triggers when records is updated. Therefore you have to fire update operation on your RITM when tasks changing their state.



There is a fake update operation that would trigger your workflow:



var ritm = new GlideRecord('sc_req_item')


ritm.get();


ritm.setWorkflow(false);


ritm..setForceUpdate(true);


ritm.update();



so you may need to create a business rule that would be fired on update operation of catalog tasks table that would do this to your ritm workflow


Hi Andrii,



Thanks for the above.   I've just tried the above, but it doesn't seem to have worked.



Setup business rule as:



find_real_file.png


find_real_file.png


Andrii
Kilo Guru

In your particular case I would recommend to make this "after" (not" before") Business Rule. and in order to troubleshoot - try removing condition "State is changing". and remove setWorkflow(false) - I think I added it automatically.



So your code would be like this:



...


ritm.get();


ritm.setForceUpdate();


ritm.update();


Hi Andrii,



Thanks for the above, I've made the above changes, but the RITM is remaining open if I close the manually created task last.



I have seen the OOTB there is the business rule 'SNC - Run parent workflows'.



Do you know why this does not trigger the workflow and if this needs amending in some form?



Thanks



Sam