Completing a Task from within a CreateListener?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2013 01:37 PM
Is there any way to do this? I'm working with a DelegateTask inside the TaskListener.notify() method.
Thanks,
Sheila.
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2013 11:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2013 12:55 AM
Each candidate group normally has one user in it, and my create listener assigns this user to the task.
Now, if a user is in e.g. three different groups, and approves a document once, I want to close all other approve-tasks, that will be assigned to him automatically.
Of course there is a solution: I can use exclusive gateway before each task. But there are so many tasks, that it is not a convinient option.
So I need to close this tasks automatically. Is there some way to achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2013 10:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2013 03:14 AM
Have I understood you correctly: there is a way to complete a task within TaskListener?
If so, please, give me a reference or just describe, how to do it.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2013 04:29 AM
Best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2013 12:44 AM
It turned out, that I can't just use TaskService, because while in TaskListener (create/assignment) the task is not yet persisted and it can not be found by TaskService.
I did this:
<code> taskService.complete(delegateTask.getId(), variables);</code>
And it threw exception.
By the way, I have tried other variants (which did not work for me):
- signal execution by runtimeService
<code> DelegateExecution execution = delegateTask.getExecution();
runtimeService.signal(execution.getId());</code>
- listen for the transaction commit and do my work post-commit
<code>Context.getCommandContext()
.getTransactionContext()
.addTransactionListener(TransactionState.COMMITTED, new TransactionListener() {
public void execute(CommandContext commandContext) {
taskService.complete(taskId, variables);
}
});</code>
It seemed to execute smoothly on Activiti side, but failed to commit on external transaction (Alfresco transaction), where I caught exception, that a node was changed concurrently in several transactions (other listeners do this job).
- listen for the external (Alfresco) transaction commit and do my work post-commit
I caught the same exception as previous.
Maybe it is more correct to post this question on Alfresco forums?
However, I suppose, that Alfresco-like configuration is not the unique one: other configurations also can use external transactions and face similar problems.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2013 02:50 AM
When you want the task on which you defined a task listener with create event you should be able to do this:
<blockcode>
delegateTask.getExecution().getEngineServices().getTaskService().complete(delegateTask.getId());
</blockcode>
Doesn't that work for you?
Best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2013 03:25 AM
The method you proposed does not work for me - it throws exception, that task does not exist - I have written it all above, and I suppose Ankhara33 (the author of original question) have tried the same.
By the way, I am using Activiti bundled with Alfresco 4.0.c - it is Activiti v.5.7.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2013 03:36 AM
Or have the logic in the layer above, that is calling the API. Instead of delegating the task, you can complete() it instead, based on whatever conditions there are.
