I'm setting custom properties (defined on startTask model) when starting workflows.
I want to update some of these properties after the workflow starts.
When trying to update startTask properties:
this.services.getWorkflowService().updateTask(startTask.getId(), customProps, null, null);
It fails with exception: "Unable to update task because it does not exists"
Caused by: org.alfresco.service.cmr.workflow.WorkflowException: 07020004 Impossible de mettre à jour la tâche de workflow activiti$start424424 car cette tâche n'existe pas. at org.alfresco.repo.workflow.activiti.ActivitiWorkflowEngine.updateTask(ActivitiWorkflowEngine.java:2365) at org.alfresco.repo.workflow.WorkflowServiceImpl.updateTask(WorkflowServiceImpl.java:981)
Any idea ?
You can never update a start task. Start tasks are "pseudo"-tasks - they technically do not exist. Using the Alfresco WorkflowService it is impossible to update workflow properties after a workflow has been started. Any update needs to happen as part of task / execution listeners within the workflow itself, i.e. you can set variables to update in a currently active task, and when that task is complete, a task listener copies the relevant properties into the process instance / execution, where all the workflow properties are stored.
Thanks Axel for your response
I just want to query all workflow instances and return, for each of them a task status summary. I developped a REST API webscript to do that, but when querying tasks for each workflow instance, performances are catastrophic, that why my idea was to update workflow instance properties (adding a task summary to these properties) to avoid task query on each workflow instance.
Then two questions:
- Would you have any advise to do that ?
- Why task queries performances are so poor ? Known issue ? Misconfiguration on my side ?
You can still have a summary property on the workflow instance - you just need to set it from within the workflow itself using Activti APIs, not using the Alfresco WorkflowService.
I don't know why specifically the task queries would be slow for you - I've never had issues with those myself. You may have a badly optimised database, excessive query conditions, complex user-group relations (in case you are dealing with pooled tasks), or just too many tasks per workflow itself.
Axel, when you say
"You can still have a summary property on the workflow instance - you just need to set it from within the workflow itself using Activti APIs, not using the Alfresco WorkflowService."
Do you mean I can set and update a process variable with task summary information ?
In this case, how to access this variable from outside the workflow (WebScript) ?
Thanks for clarification..
I shouldn't need to provide examples for this when the core engine and its APIs have been documented quite extensively, i.e. in the User Guide. So when you have a TaskListener / ExecutionListener, all you need to do is use the provided execution to set variables on it. The only thing to keep in mind is that
OK thanks Axel. Last thing (to achieve my initial target): could you please confirm that when setting process instance properties this way, these properties will become accessible from Alfresco WorkflowService ?
They become accesible from the WorkflowService provided they have been defined in the model of the start task, which Alfresco uses to determine which variables get mapped in the API. I usually use a lot of aspects with optional properties for this, set on my start task via mandatory-aspects.