cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow Parallel Group Review with Move

atoops
Champ in-the-making
Champ in-the-making
Hello, I am trying to create a jbpm workflow that assigns review tasks to a group of users.  The user group would then approve the document and it would need 100% approval, if 100% is attained it would move the document to Final Document Folder with it Site Document Lib. (/sites/test/documentLibrary/D-Final-Document).  If 100% approval is not attained it moves it to a Review Needed Folder with in Site Document Lib (/sites/test/documentLibrary/C-Rejected-Updates-Needed). 

I am new so I am trying to educate myself with previous examples from the forums and docs from the wiki. My specific issue is I keep getting the following error:
"Failure: Failed to execute script 'workspace://SpacesStore/82845e4a-85cc-4a91-8153-7c1576736f07': 09220111 Mandatory task properties have not been provided! {http://www.alfresco.org/model/bpm/1.0}groupAssignee"

Where I am completely confused is I don't have groupAssignee in the process definition or in the script that calls the workflow.  Can someone take a peek and push me in the right direction.  Any help is much appreciated, as always.

SCRIPT (this is being executed with the execute script, by a folder rule when anything enters the folder)

function startWorkflow(assigneeGroup)
{
   var workflow = actions.create("start-workflow");
   workflow.parameters.workflowName = "jbpm$wf:parallelgroupreview";
   workflow.parameters.requiredApprovePercent = 100;
   workflow.parameters["bpm:workflowDescription"] = "Please review " + document.name;
   workflow.parameters["bpm:assignees"] = [people.getPerson("boss"), people.getPerson("aaron")];
   var futureDate = new Date();
   futureDate.setDate(futureDate.getDate() + 7);
   workflow.parameters["bpm:workflowDueDate"] = futureDate;
   workflow.parameters["bpm:rejectDestination"] = "/sites/test/documentLibrary/C-Rejected-Updates-Needed"
   workflow.parameters["bpm:aproveDestination"] = "/sites/test/documentLibrary/D-Final-Document"
   workflow.parameters["sendEmailNotifications"] = true;
   return workflow.execute(document);
}

function main()
{
   var name = document.name;
   var siteName = document.siteShortName;
  
   if (siteName == null)
   {
      if (logger.isLoggingEnabled())
         logger.log("Did not start workflow as the document named " + name + " is not located within a site.");
        
      return;
   }
  
   var reviewGroup = "GROUP_site_" + siteName + "_SiteManager";

   // make sure the group exists
   var group = people.getGroup(reviewGroup);
   if (group != null)
   {
      if (logger.isLoggingEnabled())
         logger.log("Starting pooled review and approve workflow for document named " + name + " assigned to group " + reviewGroup);

      startWorkflow(reviewGroup);

      if (logger.isLoggingEnabled())
         logger.log("Started pooled review and approve workflow for document named " + name + " assigned to group " + reviewGroup);
   }
   else if (logger.isLoggingEnabled())
   {
      logger.log("Did not start workflow as the group " + reviewGroup + " could not be found.");
   }
}

main();


PROCESS DEFINITION

<?xml version="1.0" encoding="utf-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:parallelgroupreview">
  <swimlane name="initiator"></swimlane>
  <start-state name="start">
    <task name="wf:submitGroupReviewTask" swimlane="initiator" />
    <transition name="" to="startreview" />
  </start-state>
  <node name="startreview">
    <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
      <foreach>#{people.getMembers(bpm_assignees)}</foreach>
      <var>reviewer</var>
    </action>
    <event type="node-enter">
      <script>
        <variable name="wf_approveCount" access="write" />
        <expression>
                    wf_approveCount = 0;
                </expression>
      </script>
    </event>
    <transition name="review" to="review" />
  </node>
  <task-node name="review">
    <task name="wf:reviewTask">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
        <actor>#{reviewer}</actor>
      </assignment>
      <event type="task-create">
        <script>
                    if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                    if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
                </script>
      </event>
    </task>
    <transition name="approve" to="endreview">
      <script>
        <variable name="wf_approveCount" access="read,write" />
        <expression>
                    wf_approveCount = wf_approveCount +1;
                 </expression>
      </script>
    </transition>
    <transition name="reject" to="endreview" />
  </task-node>
  <join name="endreview">
    <transition to="isapproved" />
  </join>
  <decision name="isapproved">
    <event type="node-enter">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
          <variable name="wf_reviewerCount" access="write" />
          <expression>people.getMembers(bpm_assignees).length;</expression>
        </script>
      </action>
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
          <variable name="wf_requiredPercent" access="write" />
          <expression>wf_requiredPercent = wf_requiredApprovePercent;</expression>
        </script>
      </action>
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
          <variable name="wf_actualPercent" access="write" />
          <expression>wf_actualPercent = ((wf_approveCount * 100) / people.getMembers(bpm_groupAssignee).length);</expression>
        </script>
      </action>
    </event>
    <transition name="reject" to="rejected" />
    <transition name="approve" to="approved">
      <condition>#{wf_actualPercent &gt;= wf_requiredApprovePercent}</condition>
    </transition>
  </decision>
  <task-node name="rejected">
    <task name="wf:rejectedParallelTask" swimlane="initiator" />
    <transition to="end">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
               var dest = companyhome.childByNamePath(bpm_rejectDestination);
               for (var i = 0; i &lt; bpm_package.children.length; i++){
                  bpm_package.children.move(dest);
               }
           </script>
      </action>
    </transition>
  </task-node>
  <task-node name="approved">
    <task name="wf:approvedParallelTask" swimlane="initiator" />
    <transition to="end">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
               var dest = companyhome.childByNamePath(bpm_aproveDestination);
               for (var i = 0; i &lt; bpm_package.children.length; i++){
                  bpm_package.children.move(dest);
               }
           </script>
      </action>
    </transition>
  </task-node>
  <end-state name="end" />
</process-definition>


LOG FILE
Is attached: catalina-daemon.txt
4 REPLIES 4

niketapatel
Star Contributor
Star Contributor
From your processdefination, It looks like you are modifying exisitng parallelreview_group_processdefinition.xml

So if you check your start task you are using - wf:submitGroupReviewTask. This task is defined in workflowModel.xml and it has mandatory aspect - bpm:groupAssignee. And while starting workflow from js, you are not providing groupAssignee so its throwing error.

I would sugget to crate new process defination with your custom task model to practice.



     <!–  Submit review to multiple people (as included in a group) –>
      <type name="wf:submitGroupReviewTask">
         <parent>wf:submitConcurrentReviewTask</parent>
         <mandatory-aspects>
            <aspect>bpm:groupAssignee</aspect>
         </mandatory-aspects>
      </type>
     

atoops
Champ in-the-making
Champ in-the-making
Thanks Niketa and Correct I was trying to edit the parallelreview_group_processdefinition.xml: Reason i edited to declare assignees that i was not having luck declaring the group correctly. 

What if i move back to the default parallelreview_group_processdefinition.xml but still adding the rejectDestinition and aproveDestinition.  Then changed my script to call a group. I have read many of the posts of folks having some trouble with this piece.  Can someone tell me what i am missing in the group assignment?

SCRIPT

function startWorkflow(assigneeGroup)
{
   var workflow = actions.create("start-workflow");
   workflow.parameters.workflowName = "jbpm$wf:parallelgroupreview";
   workflow.parameters.requiredApprovePercent = 100;
   workflow.parameters["bpm:workflowDescription"] = "Please review " + document.name;
   workflow.parameters["bpm:groupAssignee"] = people.getGroup( "GROUP_" + siteName + "_SiteManager");
   var futureDate = new Date();
   futureDate.setDate(futureDate.getDate() + 7);
   workflow.parameters["bpm:workflowDueDate"] = futureDate;
   workflow.parameters["bpm:rejectDestination"] = "/sites/test/documentLibrary/C-Rejected-Updates-Needed"
   workflow.parameters["bpm:aproveDestination"] = "/sites/test/documentLibrary/D-Final-Document"
   workflow.parameters["sendEmailNotifications"] = true;
   return workflow.execute(document);
}

function main()
{
   var name = document.name;
   var siteName = document.siteShortName;
  
   if (siteName == null)
   {
      if (logger.isLoggingEnabled())
         logger.log("Did not start workflow as the document named " + name + " is not located within a site.");
        
      return;
   }
  
   var reviewGroup = "GROUP_site_" + siteName + "_SiteManager";

   // make sure the group exists
   var group = people.getGroup(reviewGroup);
   if (group != null)
   {
      if (logger.isLoggingEnabled())
         logger.log("Starting pooled review and approve workflow for document named " + name + " assigned to group " + reviewGroup);

      startWorkflow(reviewGroup);

      if (logger.isLoggingEnabled())
         logger.log("Started pooled review and approve workflow for document named " + name + " assigned to group " + reviewGroup);
   }
   else if (logger.isLoggingEnabled())
   {
      logger.log("Did not start workflow as the group " + reviewGroup + " could not be found.");
   }
}

main();

DEFAULT PROCESS DEFINITION - parallelreview_group_processdefinition.xml (with added move actions)

<?xml version="1.0" encoding="utf-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:parallelgroupreview">
  <swimlane name="initiator"></swimlane>
  <start-state name="start">
    <task name="wf:submitGroupReviewTask" swimlane="initiator" />
    <transition name="" to="startreview" />
  </start-state>
  <node name="startreview">
    <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
      <foreach>#{people.getMembers(bpm_groupAssignee)}</foreach>
      <var>reviewer</var>
    </action>
    <event type="node-enter">
      <script>
        <variable name="wf_approveCount" access="write" />
        <expression>
                    wf_approveCount = 0;
                </expression>
      </script>
    </event>
    <transition name="review" to="review" />
  </node>
  <task-node name="review">
    <task name="wf:reviewTask">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
        <actor>#{reviewer}</actor>
      </assignment>
      <event type="task-create">
        <script>
                    if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                    if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
                </script>
      </event>
    </task>
    <transition name="approve" to="endreview">
      <script>
        <variable name="wf_approveCount" access="read,write" />
        <expression>
                    wf_approveCount = wf_approveCount +1;
                 </expression>
      </script>
    </transition>
    <transition name="reject" to="endreview" />
  </task-node>
  <join name="endreview">
    <transition to="isapproved" />
  </join>
  <decision name="isapproved">
    <event type="node-enter">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
          <variable name="wf_reviewerCount" access="write" />
          <expression>people.getMembers(bpm_groupAssignee).length;</expression>
        </script>
      </action>
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
          <variable name="wf_requiredPercent" access="write" />
          <expression>wf_requiredPercent = wf_requiredApprovePercent;</expression>
        </script>
      </action>
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
          <variable name="wf_actualPercent" access="write" />
          <expression>wf_actualPercent = ((wf_approveCount * 100) / people.getMembers(bpm_groupAssignee).length);</expression>
        </script>
      </action>
    </event>
    <transition name="reject" to="rejected" />
    <transition name="approve" to="approved">
      <condition>#{wf_actualPercent &gt;= wf_requiredApprovePercent}</condition>
    </transition>
  </decision>
  <task-node name="rejected">
    <task name="wf:rejectedParallelTask" swimlane="initiator" />
    <transition to="end">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
               var dest = companyhome.childByNamePath(bpm_rejectDestination);
               for (var i = 0; i &lt; bpm_package.children.length; i++){
                  bpm_package.children.move(dest);
               }
           </script>
      </action>
    </transition>
  </task-node>
  <task-node name="approved">
    <task name="wf:approvedParallelTask" swimlane="initiator" />
    <transition to="end">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
               var dest = companyhome.childByNamePath(bpm_aproveDestination);
               for (var i = 0; i &lt; bpm_package.children.length; i++){
                  bpm_package.children.move(dest);
               }
           </script>
      </action>
    </transition>
  </task-node>
  <end-state name="end" />
</process-definition>

niketapatel
Star Contributor
Star Contributor
Please try this.

I have done required changes. Below script should start workflow. Please check my inline comment.



function startWorkflow(assigneeGroup)

{

   var workflow = actions.create("start-workflow");

   workflow.parameters.workflowName = "jbpm$wf:parallelgroupreview";

   workflow.parameters.requiredApprovePercent = 100;

   workflow.parameters["bpm:workflowDescription"] = "Please review " + document.name;

   // niketa - here siteName var would be undefined
   //workflow.parameters["bpm:groupAssignee"] = people.getGroup( "GROUP_" + siteName + "_SiteManager");
   
   
   workflow.parameters["bpm:groupAssignee"] = assigneeGroup

   var futureDate = new Date();

   futureDate.setDate(futureDate.getDate() + 7);

   workflow.parameters["bpm:workflowDueDate"] = futureDate;

   workflow.parameters["bpm:rejectDestination"] = "/sites/test/documentLibrary/C-Rejected-Updates-Needed"

   workflow.parameters["bpm:aproveDestination"] = "/sites/test/documentLibrary/D-Final-Document"

   workflow.parameters["sendEmailNotifications"] = true;

   return workflow.execute(document);

}



function main()

{

   var name = document.name;

   var siteName = document.siteShortName;



   if (siteName == null)

   {

      if (logger.isLoggingEnabled())

         logger.log("Did not start workflow as the document named " + name + " is not located within a site.");



      return;

   }



   var reviewGroup = "GROUP_site_" + siteName + "_SiteManager";



   // make sure the group exists

   var group = people.getGroup(reviewGroup);

   if (group != null)

   {

      if (logger.isLoggingEnabled())

         logger.log("Starting pooled review and approve workflow for document named " + name + " assigned to group " + reviewGroup);



      //startWorkflow(reviewGroup);
      //niketa - need to pass js group scriptNode object
      startWorkflow(group);



      if (logger.isLoggingEnabled())

         logger.log("Started pooled review and approve workflow for document named " + name + " assigned to group " + reviewGroup);

   }

   else if (logger.isLoggingEnabled())

   {

      logger.log("Did not start workflow as the group " + reviewGroup + " could not be found.");

   }

}



main();

atoops
Champ in-the-making
Champ in-the-making
niketapatel,

Thanks so much for your time and assistance.  This solved the issue of applying the group to the workflow and starting the workflow as desired. 

I still am not getting the file to move when approved or rejected.  So I will continue to dig on that.  I will create a separate post for that.

Truly appreciate your help!!!