cancel
Showing results for 
Search instead for 
Did you mean: 

Triggering Rule when a document is approved

fitek
Champ in-the-making
Champ in-the-making
I'm trying to figure out how to trigger a rule so when a parallel approval workflow is completed and the document in the workflow is approved, I can move the document.

I've tried adding a rule by select "more…" from the criteria drop down and using "outcome" and "status".  I tried outcome contains "approved" and when that didn't work I tried status contains "completed."   I'd like to move approved docs from a Pending folder to a "Approved" folder.

Thoughts?

I tried to display the workflow history in the document-details as a temporary work around, but queries to
/alfresco/service/api/node/workspace/SpacesStore/fe3f8bfc-ea1d-4a5f-b5ac-cbbf49f2b805/workflow-instances?status=completed
Return no data.

7 REPLIES 7

mitpatoliya
Star Collaborator
Star Collaborator
You said you can move the document so I am assuming that during final approval your documents goes to some space lets say "finalapproved".
You can create a rule on that space that whenever any document come to this space apply this rule.
So that rule will always be triggered when document got final approval and moving in to that space.

But It seems there is something I missed Smiley Happy

fitek
Champ in-the-making
Champ in-the-making
Just to clarify:  I set a rule up to move the document but it doesnt work, so no, I can't move a document. 

Im not sure what Ive done wrong or if it is even possible to create a rule that triggers off a workflow's outcome.  Actually, ANYTHING that would allow me to either copy/move a document or create a PDF upon successful approval would work for me.

Frankly I dont understand what the point of the approval workflows is if they don't have any effect on the documents that are being approved… so I assume there must be some relatively simple way to configure Alfresco to perform an action on the documents if the approval workflow's outcome equals "approved"?

mitpatoliya
Star Collaborator
Star Collaborator
Ok, I got your problem.
What you can do is in your process definition file of workflow you can add piece of script code
which will be invoked during approval
which will move document to your desired location.

atoops
Champ in-the-making
Champ in-the-making
Mits,

Do you have any example process definition of this. 

I am trying to do this with this process definition and not having any luck.  Can you see anything that is missed?


<?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>

SCRIPT executing the workflow:

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();

fgjohnson
Champ in-the-making
Champ in-the-making
Hi fitek,
Did you ever get this resolved?
It is exactly what I am looking for
Is coding necessary, or is it possible using folder rules in localhost:8080/share?

There should be a repository of simple solutions…

varshini
Champ in-the-making
Champ in-the-making
Hi Everyone,

My requirement is to trigger a custom workflow when an xml file is dropped in a particular folder and use the contents of the xml file during the process of workflow.

I started my requirement with following steps in mind
a. Initially I tried to create rule for a folder which triggers a simple workflow available in options (with Approve, Reject) when an xml file is dropped into a folder - which is not triggering the rule.
b. If it triggers how can I trigger a custom workflow from a rule?
c. How to use same xml file at different points of the workflow?
d. How to grab the elements in xml and use them throughout the workflow?

Can anyone help me. I am struck at step 1.I am not able to trigger a rule. Please suggest your ideas asap. Any help would be needful.

Thanks,
Varshini

varshini
Champ in-the-making
Champ in-the-making
Hi Everyone,

As mentioned in my previous post. I am able to achieve Step 1. But my concern is every time I have to run rules manually by clicking on 'Run Rules for this folder'. How to trigger them automatically as soon as file enters the folder. Also I need help with Steps 2,3,4 i.e triggering my custom workflow and accessing the file throughout workflow. Please help me.