Wait for condition proceeds incorrectly

Todd Chaikin
Tera Contributor

I have a "Wait for condition" in my workflow that waits to see if all tasks are closed before proceeding (unfortunately this workflow has some script-generated tasks, otherwise I would normally use a Join).

 

The issue I'm running into is that if a requestor, who does not have access to the catalog task table, makes a comment on the request while the workflow is sitting on this activity, it incorrectly proceeds to the next step in the flow.

 

Ideally the workflow should be evaluating the below condition as an administrator and not as the last user to update the RITM.

 

Does anyone have any suggestions for how I can prevent the workflow from continuing prematurely?

 

var gr_tsk = new GlideRecord("sc_task");
gr_tsk.addQuery('request_item', current.sys_id);
gr_tsk.addQuery('state', '!=', '3');
gr_tsk.addQuery('state', '!=', '4');
gr_tsk.addQuery('state', '!=', '7');
//gr_tsk.addQuery('wf_activity', '');
gr_tsk.query();
if (gr_tsk.next()) {
   answer = false;
   gs.log('answer = false ' + current.sys_id); 
} else {
   answer = true;
}

 

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Hi Todd,

Generally, scripts that run as the last user to approve, close a task, or otherwise interact with the RITM can be set back to run as the System account by inserting a 5 second timer before the activity, but with that test case you describe it doesn't sound like that would do the trick.  You could try changing the wait for condition to a (hidden) variable that's populated, then create an after Update Business Rule on the sc_task table when Active changes to false with a script to populate the variable if there are no other active catalog tasks under the same RITM. 

I think I may have actually solved it... preliminary testing is successful anyway. What I ended up doing was nesting my existing script in the "else" condition of an if that checks whether the user has 'itil' or not. Wasn't sure whether it would allow me to do a gs.getUser in the "Wait for condition" within the workflow, but it seems to be working.

if (!gs.getUser().hasRole('itil')) {
	// Prevent erroneous workflow procession for non-ITIL users
	answer = false;
}
else {
	var gr_tsk = new GlideRecord("sc_task");
	gr_tsk.addQuery('request_item', current.sys_id);
	gr_tsk.addQuery('state', '!=', '3');
	gr_tsk.addQuery('state', '!=', '4');
	gr_tsk.addQuery('state', '!=', '7');
	//gr_tsk.addQuery('wf_activity', '');
	gr_tsk.query();
	if (gr_tsk.next()) {
		answer = false;
		gs.log('answer = false ' + current.sys_id); 
	} else {
		answer = true;
	}
}