AnsweredAssumed Answered

Assignment Event in workflow

Question asked by irenailievska1 on Dec 14, 2015
Latest reply on Dec 16, 2015 by jbarrez
Hi,
I have a bit of a problem with Activiti. I wish to add permission for viewing a document to a candidate group. But if I use the assignment event that is integrated in a user task, then when I click to finish the task - the task doesn't redirect. It stays on the same window and if I go Home the task is finished - removed from the My tasks dashlet. If I remove the assignment event then everything works fine.
I found out that the assignment event fires before create task, on save and close button, reassign, and in my case on Claim button - so when the task is assigned to a group the permissions are added only to the person that claims the task.
Below is a part of the code I am using. Any kind of help is welcomed.

<userTask id="task1" name="task 1" activiti:candidateGroups="${swf_archive1.properties.authorityName}" activiti:formKey="swf:taskFirst">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[
                                      //////////////some code
                            ]]></activiti:string>
          </activiti:field>
          <activiti:field name="runAs">
            <activiti:string><![CDATA[admin]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="assignment" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[var userName = task.assignee;
                      
                     for(var i = 0; i < bpm_package.children.length; i++) {

                        var resource = bpm_package.children;
                        
                        if(!resource.getSiteShortName()){
                           resource.setPermission("Consumer", userName);
                        }   
                         else
                         {
                           var siteName = resource.getSiteShortName();
                           var site = siteService.getSite(siteName);
                           if(!site.isMember(userName)){
                              resource.setPermission("Consumer", userName);
                              
                           }
                        }
                  }]]></activiti:string>
          </activiti:field>
          <activiti:field name="runAs">
            <activiti:string><![CDATA[admin]]></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[
                                       //////////////some code
                  ]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>


Thanks in advanced,
Irena

Outcomes