Best Practice: Waiting for task completion in workflow

kristenankeny
Tera Guru

We had a business need to have flexible task creation for catalog items, dependent upon the a variable choice selection. For example:

On the Email form, there is a field called "type":

If type is "Company" - create two tasks for fulfillment

If type is "External" - create three tasks for fullfillment

My solution was to create a new table to capture what catalog item, what variable, variable option, task information, and task order. I'm allowing for concurrent and sequential tasks, depending upon form need. This is controlled by a task order.

In my workflow, I script the task creation like this:

var t = new GlideRecord('u_task_assignments');

t.addQuery('u_request_item',current.cat_item);

t.orderBy('u_task_order');

t.query();

var cisupp = '';

var ci = new GlideRecord('cmdb_ci');

ci.addQuery('sys_id',current.cmdb_ci);

ci.query();

if(ci.next()){

  cisupp = ci.u_level_ii_support_group;

}

while(t.next()){

  var v = t.u_variable.name;

  if(current.variables[v] == t.u_variable_option.value){

  var ct = new GlideRecord('sc_task');

  ct.initialize();

  if(t.u_assignment_group != ''){

  ct.assignment_group = t.u_assignment_group;

  }

  else{

  ct.assignment_group = cisupp;

  }

  ct.short_description = t.u_task_short_description;

  ct.description = t.u_task_description;

  ct.request_item = current.sys_id;

  ct.order = t.u_task_order;

  ct.priority = 3;

  ct.u_requested_for = current.u_requested_for;

  ct.parent = current.sys_id;

  ct.location = current.location;

  ct.u_office_cube = current.u_office_cube;

  ct.u_phone = current.u_phone;

  ct.due_date = current.due_date;

  if(t.u_task_order == 1){

  ct.state = 1;

  }

  else{

  ct.state = -5;

  }

  ct.insert();

  }

}

Only the tasks with order of 1 are created with "Open" state. The others are created with "Pending", and then a business rule is controlling changing them to Open when all previous tasks closed.

In my workflow, I need to wait until all of the tasks are closed. I'm currently controlling this with an "If' activity, then looping back through (currently set to 1 minute for testing, would be increased in production).

find_real_file.png

Is there a better way to control this? Could the business rule that controls my tasks be adjusted to send a notification to the workflow that the tasks are all completed and it can move forward? Has anyone done something like this previously or have any suggestions?

Thanks,

Kristen

1 ACCEPTED SOLUTION
5 REPLIES 5

Johnny...once again, you are the man...


setting parent field solved the problem !



BTW: i got my new car tag yesterday...following your suit



ITSM.jpeg