Scripting the Wait for Completion option?

dbrown1
Kilo Contributor

A bit of background: I need to create a number of tasks for different groups based on whether or not a field is filled out in the item they're requesting. I've done this by implementing a turnstile that creates catalog tasks, but the built-in 'Catalog Task' doesn't create multiple tasks in that scenario (if you do a workflow: Start -> Turnstile(3) -> Catalog Task -> End, it will create one task, then end. using logging, I've verified it does go through the turnstile 3 times; only the task part doesn't repeat)

Long story short, I'm creating the task manually with a Run Script, and I'm trying to duplicate the 'Wait for Completion' functionality of the built-in catalog task. I've tried tsk.vars.wait_for_completion (errors the script completely - no tasks completed), tsk.variables.wait_for_completion (doesn't error the script, but doesn't cause it to wait for completion either).

Looking through the activity definition for creating tasks, I see a lot of functionality I don't want to have to duplicate on this manual task. Does anyone know either:
1) an easy way to script the 'wait for completion' functionality, or
2) how I can create multiple tasks in a turnstile?

2 REPLIES 2

mikep1
Kilo Explorer

Did you ever find a way to do this?

I also have a similar situation where I have multiple tasks that need to be created and the "Wait for Completion" depends on a value in the request. For example, I have tasks to create a LAN ID, Outlook account, application #1 account, application #2 account, etc. When the value in the request is set to "create", I need the LAN ID Task to have the Wait for Completion before the other Tasks because the other Tasks need that LAN ID. If it's "remove", they don't need to wait.

The sample above only has 1 "wait for condition" but my real life situation has multiple so it's not as simple as having an "if" statement and different paths.

Thanks,
Mike


dbrown1
Kilo Contributor

I couldn't, but I used the 'Wait For Condition' activity to do a workaround...



// Set the variable 'answer' to true or false to indicate if the condition has been met or not.
if(current.variables.request_type == 'create'){
var task = new GlideRecord('sc_task');
task.addQuery('request_item',current.sys_id);
task.addQuery('state', '!=', 3); // 1 of our 3 closed states
task.addQuery('state', '!=', 4); // 2 of our 3 closed states
task.addQuery('state', '!=', 7); // 3 of our 3 closed states
task.addQuery('short_description', 'LAN ID')
task.query();
if (task.next()){answer = false;}
else {answer = true;}
} else if(current.variables.request_type == 'remove'){
answer = true;
}

Something like this should work, if you modify it to match your conditions.