I have two task listeners,the first on event="create"
the second on event="complete"
.
In the first i'm counting files when task was created, in the second when task completed and looking if the number of files is equal throw an error. But this not work, i have ReferenceError: "count" is not defined
.
<extensionElements>
<activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string><![CDATA[
var count = 0;
for (var i = 0; i < bpm_package.children.length; i++)
{
count++;
}
]]></activiti:string>
</activiti:field>
</activiti:taskListener>
<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string><![CDATA[
var count_new = 0;
for (var i = 0; i < bpm_package.children.length; i++)
{
count_new++;
}
if (count ==count_new)
{
var message = "\n\nAdd files\n";
throw new Error(message + "\n");
}
]]></activiti:string>
</activiti:field>
</activiti:taskListener>
</extensionElements>
I solved the problem of how to define a variable. You need to add
execution.setVariable ('zvernennya_count', count);
to the first task listener.But it does not solve my problem of testing attachments, because the variable
count
is defined once, and the task has multi-user access, and when the first users task is completed, the next users task already has variablecount_new
different fromcount
.You are getting ReferenceError because that "count" variable is not visible to other Listener.
If you need to persist the value of variable you have to define variable in the workflow model use that variable in place of local variable count.
http://docs.alfresco.com/4.0/concepts/wf-task-model.html
This should give you good starting point.