- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2016 08:18 AM
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).
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2016 09:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2016 09:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2016 09:58 AM
Thanks! I guess when I tried that activity before, I didn't script the output correctly. After some trial and error, I have my script working in the wait for condition now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2016 01:01 PM
Hey again Johnny !!
This script doesn't seem to be working for us, however we are creating tasks via an unusual method...by values entered into the catalog item. The "run script" workflow step that creates tasks:
var computerNameList = current.variables.ComputerNameList.toString();
var computerNames = computerNameList.split('\n');
for(var i = 0; i < computerNames.length; i++)
{
if(computerNames[i].indexOf("Validated:") > -1)
{
var name = computerNames[i].replace('Validated:','');
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request_item = current.sys_id;
gr.short_description = "SCCM Task for " + name;
gr.assignment_group = "e9a21f8e379ca20024a67c1643990e75";
gr.assigned_to = "48039f8e379ca20024a67c1643990ebb";
gr.u_computer_name = name;
gr.priority = current.priority;
gr.u_collection_id = current.variables.collection_id;
gr.state = '2';
gr.stage = 'delivery'
gr.insert();
}
else if(computerNames[i].indexOf("Unknown:") > -1)
{
var rawName = computerNames[i];
var name = computerNames[i].replace('Unknown:','');
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request_item = current.sys_id;
gr.short_description = "SCCM Task for " + rawName;
gr.assignment_group = "e9a21f8e379ca20024a67c1643990e75";
gr.assigned_to = "48039f8e379ca20024a67c1643990ebb";
gr.u_computer_name = name;
gr.priority = current.priority;
gr.u_collection_id = current.variables.collection_id;
gr.state = '2';
gr.stage = 'delivery'
gr.insert();
}
}
Not sure what we will do about a "all tasks closed" check on this workflow...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2016 01:05 PM
I think you need to set the "parent" field on the created sc_task records to the sys_id of the RITM the workflow is running on.
gr.parent = current.sys_id +"";
I always add an empty string to sys_id fields to ensure they copy correctly.
Also, coding with the variable name "gr" is dangerous. I would use "new_task_gr" or something.