We have a clients that process many workflows in a day and they would like us to write a function to set the status on many workflows at a time. Can you provide some code/pseudocode on how we this would be write this?
Thanks
Ron
We have clients that process many workflows in a day and they would like us to write a function to set the status on many workflows at a time. Can you provide some code/pseudocode on how we this would be write this?
Thanks
Ron
Hi Ron,
I believe you mean set the status of many task instances at a time? Because the status of the workflow is always set internally by Workflow Studio depending on the flow. You can retrieve a list of task instances for a specified user like this:
var
ATasks: TTaskInstanceList;
begin
ATasks := TTaskInstanceList.Create(TTaskInstanceItem);
try
WS.TaskManager.LoadTaskInstanceList(ATasks, tfUser, 'username', true
{only incomplete tasks});
{other options:
WS.TaskManager.LoadTaskInstanceList(ATasks, tfUsers,
'user1,user2,user3', true );
WS.TaskManager.LoadTaskInstanceList(ATasks, tfWorkIns, '23', true );
//To see tasks of workflow instance 23
}
if ATasks.Count > 0 then
ShowMessage('User has pending tasks.')
else
ShowMessage('User doesn't have pending tasks.');
// Iterate through ATasks collection to see the list of tasks
finally
ATasks.Free;
end;
end;
Then for each task instance you can modify the status like this (TI is a TTaskInstance object):
TI.Status := ‘closed’; //set the status to a final status you want
WorkflowStudio.TaskManager.SaveTaskInstance(TI);
Thanks for the reply Wagner,
"I believe you mean set the status of many task instances at a time? " Yes.
Is there a method to perform this work from the grid on the selected items?
Is there a way to determine what are the valid TI.Status are for a TaskInstance?
Thanks
Ron
From the current builtin dialog there is no such functionality. But if you have a custom form, then of course you can add such code.
From the task instance, you can get the list of valid status
TI.TaskDef.StatusList // StatusList is a TStrings object
Correction, you should use
for I := 0 to TI.TaskDef.StatusCount - 1 do
TI.TaskDef.StatusName;
You can also check if the status is a completion status (finalizes the task) by checking TI.TaskDef.StatusCompletion
Thanks I'll give it try...