cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow custom props update

vincent-kali
Star Contributor
Star Contributor

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 11

vincent-kali
Star Contributor
Star Contributor

Still getting some issues when trying to set process custom properties and get it using worklflow service API.

Following axel recommendations, I did the following:

1) create aspect with optionnal properties and add it as mandatory aspect to process start task model

2) set these properties in ScriptTask / Scriptexecution listeners.

Result observed:

I defined two process listeners (org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener): one on 'start' event, one on 'end' event.

When setting the custom property by script on start event execution listener, property is set and accessible using workflow service. When setting the property on 'end' event (or from any other ScriptExecutionListener/ScriptTaskListener), the property is not set (or not visilble from workflow service).

Any idea ?

Thanks,

Vincent

vincent-kali
Star Contributor
Star Contributor

Just to complete this topic: as Axel explained above, any process property can be set from task/process activiti listener and read by workflow service as soon as the property is defined as a process (start task) property.

Listener code:

DelegateExecution execution = task.getExecution();
ProcessInstance processInstance = execution.getEngineServices().getRuntimeService().createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
execution.getEngineServices().getRuntimeService().setVariable(processInstance.getId(), "myPrefix_myProcessVariable", "myValue");

Wf model

...

<!-- Submit process task -->
<type name="myPrefix:submitTask">
<parent>bpm:startTask</parent>

<mandatory-aspects>
<aspect>myPrefix:myAspect</aspect>
</mandatory-aspects>
</type>

.....

<aspect name="myPrefix:myAspect">
<properties>

<property name="myPrefix:myProcessVariable">
<type>d:text</type>
<mandatory>false</mandatory>
<index enabled="true">
<tokenised>false</tokenised>
<facetable>true</facetable>
</index>
</property>

</properties>
</aspect>

....