cancel
Showing results for 
Search instead for 
Did you mean: 

Update Workflow Task Property via JavaScript

joaotpd
Champ on-the-rise
Champ on-the-rise
Hi all,

How can I update a task property using JavaScript? The code below does not work:

<javascript>
var task = workflow.getTask("jbpm");
task.properties["wf:destinationUser"] = "new.user";
task.save();
</javascript>

Anyone?

Sure it must be simple, but i can find it anywhere.

Thanks!

João
4 REPLIES 4

afaust
Legendary Innovator
Legendary Innovator
Hello,

you can't update the properties of a task like you would on a node. What you should be able to do is the following:


var task = workflow.getTask("jbpm");
var properties = task.properties;
properties["wf:destinationUser"] = "new.user";
task.properties = properties;


There is no need to call save() as the assignment will already trigger the update in the database. Please note that this code, while apparently trivial and using a seemingly unnecessary re-assignment, is required due to the way the JavaScript environment and the involved Java objects interact.

Regards
Axel

joaotpd
Champ on-the-rise
Champ on-the-rise
Hello Alex and many thanks for the reply.

I tried the code that you suggested, but does not work. More specifically the last line. I get the following error:

<javascript>
Java class "org.alfresco.repo.workflow.jscript.JscriptWorkflowTask" has no public instance field or method named "properties"
</javascript>

I suppose I can "get", but I can't "set"…

Any ideas?! …

Thanks again,

João

afaust
Legendary Innovator
Legendary Innovator
Hello,

try <blockcode>task.setProperties(properties);</blockcode> instead. It appears that in this instance, the <blockcode>task.properties</blockcode> is mapped to the getProperties() method, but the assignment is not mapped to the setProperties() equivalent. This is also an oddity of the JavaScript-Java boundary - the get/set methods don't always align properly based on parameter type definition and runtime resolution.

Regards
Axel

joaotpd
Champ on-the-rise
Champ on-the-rise
It works! Thanks for the help Alex… and the explanation …

Regards,

João