Workflow custom props update

cancel
Showing results for 
Search instead for 
Did you mean: 
vincent-kali
Established Member

Workflow custom props update

Hi all,

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 ?

Thanks,

Vincent

11 Replies
afaust
Master

Re: Workflow custom props update

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.

vincent-kali
Established Member

Re: Workflow custom props update

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 ?

Thanks,

Vincent

afaust
Master

Re: Workflow custom props update

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.

vincent-kali
Established Member

Re: Workflow custom props update

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..

VIncent

vincent-kali
Established Member

Re: Workflow custom props update

In particular, could you share an example of 'setting it from within the workflow itself using Activti APIs'

Thanks in advance :

afaust
Master

Re: Workflow custom props update

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

  1. you need to transform the prefixed QName of a property / association to use '_' instead of ':'
  2. Node references need to be stored as ActivitiScriptNode / ActivitiScriptNodeList
  3. if you want to transfer the value of a variable set on the task (via a form) to an identically named variable on the process, you need to explicity obtain the global execution / process instance via the Activiti RuntimeService
    Code snippet: processInstance = execution.getEngineServices().getRuntimeService().createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult()
vincent-kali
Established Member

Re: Workflow custom props update

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 ?

afaust
Master

Re: Workflow custom props update

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.

vincent-kali
Established Member

Re: Workflow custom props update

Great ! I'll test this and post here results. Thanks again.