cancel
Showing results for 
Search instead for 
Did you mean: 

email in custom workflow

darklord
Champ in-the-making
Champ in-the-making
i have created few custom workflows in wcm with pooled actors. just want to have an idea how to send email notifications on approval/submit and other transitions to Group users.
any references or major steps list down will be appreciated
10 REPLIES 10

jpotts
World-Class Innovator
World-Class Innovator
You can leverage the built-in Mail action, either by executing it from some Alfresco JavaScript in the process or from a Java-based jBPM action. There's an example of this in the Alfresco Developer Guide. In case you don't have it, here's some of the code:

In the case of the latter, the process def would look something like:

<event type="node-enter">
        <action class="com.someco.bpm.ExternalReviewNotification"/>
</event>

And the Java class would look something like:

    String recipient = (String) executionContext.getVariable(ExternalReviewNotification.RECIP_PROCESS_VARIABLE);

    StringBuffer sb = new StringBuffer();
    sb.append("You have been assigned to a task named ");
    sb.append(executionContext.getToken().getNode().getName());

    …SNIP – Continue to build the body as appropriate…
      
    Action mailAction = this.actionService.createAction(MailActionExecuter.NAME);
    mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, ExternalReviewNotification.SUBJECT);       
    mailAction.setParameterValue(MailActionExecuter.PARAM_TO, recipient);
    mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, ExternalReviewNotification.FROM_ADDRESS);
    mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, sb.toString());
       
    this.actionService.executeAction(mailAction, null);

In your case, you have know the group, not the raw email address. You'd have to look at the mail action executer to see if it can do the work of figuring out the email addresses of the group members. Or, you can always write your own mail action using the Java mail API.

Hope that helps,

Jeff

darklord
Champ in-the-making
Champ in-the-making
Thanks Jeff . it is pretty helpful to know one more mechanism. how ever in the mean while i did my work using this easy(might be not good) work around


<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
            <script>
               <expression>  
                     for each (user in people.getMembers(people.getGroup('GROUP_Company'), false)){
                        var mail = actions.create("mail");
                        mail.parameters.to = user.properties["cm:email"];
                        mail.parameters.subject = "One or more  Content has been sent to you for Review.";
                        mail.parameters.from = initiator.properties["cm:email"];
                        mail.parameters.text = "New  content has been submitted and are awaiting your review!";
                        mail.execute(bpm_package);
                     }
               </expression>
            </script>
         </action>

just wanted to know how can i add comments in email that user has provided while rejecting or approving workflow content

Thanks for your support

jpotts
World-Class Innovator
World-Class Innovator
There's a bpm:comment property of bpm:task so if your tasks are sub-types of that it seems like you should be able to get the comment out of bpm_comment.

Jeff

darklord
Champ in-the-making
Champ in-the-making
i appended 
bpm_package.children[0].properties["bpm_comment"] 
but didnt work .. Smiley Indifferent

darklord
Champ in-the-making
Champ in-the-making
 token.comments.get(0).message

i got the comments using this command…thanks

giorgio
Champ in-the-making
Champ in-the-making
how to send an email to all users in parallel workflows?
Thanks

jpotts
World-Class Innovator
World-Class Innovator
If you are talking about the out-of-the-box parallel processes, the assignees are either in bpm_assignees for users or bpm_groupAssignee for group assignment. You can iterate over the users in bpm_assignees and then send an email using the out-of-the-box mail action or you can write your own action that uses the Java Mail API to send the email. For group assignment, you'll have to ask the group for its member list and then iterate over those.

Hope that helps,

Jeff

giorgio
Champ in-the-making
Champ in-the-making
If you are talking about the out-of-the-box parallel processes, the assignees are either in bpm_assignees for users or bpm_groupAssignee for group assignment. You can iterate over the users in bpm_assignees and then send an email using the out-of-the-box mail action or you can write your own action that uses the Java Mail API to send the email. For group assignment, you'll have to ask the group for its member list and then iterate over those.

Hope that helps,

Jeff

Sorry, my question is not about email, is about permisions on documentos, here is the truth post

Hello good again and see if you can help me with this little problem, as I have discussed my job with eh managed workflows, specifically the review workflow, user to user, then once done, I've arranged to do the same but in the parallel flow of users, ie a user in to multiple users, and wonder if the code is the same, because in a work flow and the other not? in the two streams and send the mail perfectly task too, but in the workflow Parallel seems not remove the permissions, however, if I print in the mail the variable "acl" that contains the permissions that I removing, at the end if that contains the permissions that was supposed to wear.

processdefinition.xml you put two of each of the streams that you may see the differences:

This is the review_processdefinition.xml that if it works well, removes the permissions inheritance and assign new ones.

 xml version = "1.0" encoding = "UTF-8"? 

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:review">

     <swimlane name="initiator" />

     <start-state name="start">
         <task name="wf:submitReviewTask" swimlane="initiator" />
         <transition name="" to="review" />
     </ start-state>

     <swimlane name="reviewer">
         <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
             <actor> # (bpm_assignee) </ actor>
         </ assignment>
     </ swimlane>

     <task-node name="review">
         <task name="wf:reviewTask" swimlane="reviewer">
             <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="" to="completed" />

     <event type="node-enter">
<! - Update the status to Rejected when we enter this task ->
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>



for (var i = 0, i <bpm_package.children.length i + +)
(

bpm_package.children [i]. properties [ "my: priority"] = bpm_workflowPriority;
bpm_package.children [i]. properties [ "my: ultimoestado"] = "Pendent";
bpm_package.children [i]. properties [ "my: ultimotecnico"] = bpm_assignee.properties [ "cm: userName"];
if (bpm_package.children [i]. properties [ "my: state"] == null) (
bpm_package.children [i]. properties [ "my: state"] = "Pendent";
bpm_package.children [i]. properties [ "my: tecnico"] = bpm_assignee.properties [ "cm: userName"];
) else (
bpm_package.children [i]. properties [ "my: state"] [bpm_package.children [i]. properties [ "my: state."] length] = "Pendent";
bpm_package.children [i]. properties [ "my: tecnico"] [bpm_package.children [i]. properties [ "my: tecnico."] length] = bpm_assignee.properties [ "cm: userName"];
)
bpm_package.children [i]. save ();


 

bpm_package.children [i]. setInheritsPermissions (false);

bpm_package.children var permissions = [i]. permissions;
var acl = [];
for (var j = 0, j <permissions.length j + +)
(
acl = permissions [j]. (";"); split
var perm = acl [2];
var grp = acl [1];
bpm_package.children [i]. removePermission (perm, grp);
)


bpm_package.children [i]. setPermission ( "Consumer" bpm_assignee.properties [ "cm: userName"]);



)

            var mail = actions.create ( "mail");
            bpm_assignee.properties mail.parameters.to = [ "cm: email"];
            mail.parameters.subject = "Notice of assignment" + bpm_workflowDescription;
            mail.parameters.from = "noreply@edu.gva.es";
            mail.parameters.text = "No reply to this task mensaje.La" + bpm_workflowDescription + "has been assigned must review here http://notasinternas.edu.gva.es";
            mail.execute (bpm_package);

</ script>
</ action>
</ event>

     </ task-node>

     <task-node name="completed">
     <event type="node-enter">
<! - Update the status to Rejected when we enter this task ->
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
for (var z = 0, z <bpm_package.children.length, z + +)
(

bpm_package.children [z]. properties [ "my: priority"] = bpm_workflowPriority;
bpm_package.children [z]. properties [ "my: ultimoestado"] = "acabat";
bpm_package.children [z]. properties [ "my: ultimotecnico"] = bpm_assignee.properties [ "cm: userName"];
if (bpm_package.children [z]. properties [ "my: state"] == null) (
bpm_package.children [z]. properties [ "my: state"] = "acabat";
bpm_package.children [z]. properties [ "my: tecnico"] = bpm_assignee.properties [ "cm: userName"];
) else (
bpm_package.children [z]. properties [ "my: state"] [bpm_package.children [z]. properties [ "my: state."] length] = "acabat";
bpm_package.children [z]. properties [ "my: tecnico"] [bpm_package.children [z]. properties [ "my: tecnico."] length] = bpm_assignee.properties [ "cm: userName"];
)
bpm_package.children [z]. save ();
)
</ script>
</ action>
</ event>
         <transition name="" to="end" />
     </ task-node>
     <end-state name="end" />

</ process-definition>


And this one is parallellreview_proccessdefinition.xml when the mail arrives but the task also reaches all users but it seems that does not cut the inheritance and does not assign new permissions to the document.

 xml version = "1.0" encoding = "UTF-8"? 

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:parallelreview">

     <swimlane name="initiator"> </ swimlane>

     <start-state name="start">
         <task name="wf:submitParallelReviewTask" swimlane="initiator" />
         <transition name="" to="startreview"/>
     </ start-state>

     <node name="startreview">
         <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
             <foreach> # (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>
         </ task>
<event type="node-enter">
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>


for (var i = 0, i <bpm_package.children.length i + +)
(

bpm_package.children [i]. setInheritsPermissions (false);

bpm_package.children var permissions = [i]. permissions;
var acl = [];
for (var j = 0, j <permissions.length j + +)
(
acl = permissions [j]. (";"); split
var perm = acl [2];
var grp = acl [1];
bpm_package.children [i]. removePermission (perm, grp);

            var mail = actions.create ( "mail");
            reviewer.properties mail.parameters.to = [ "cm: email"];
            mail.parameters.subject = "Notice of assignment;
            mail.parameters.from = "noreply@edu.gva.es";
            mail.parameters.text = acl + "Do not respond to this mensaje.Tiene an assignment should review http://notasinternas.edu.gva.es here";
            mail.execute (bpm_package)

)

bpm_package.children [i]. setPermission ( "Coordinator", reviewer.properties [ "cm: userName"]);


)

            var mail = actions.create ( "mail");
            reviewer.properties mail.parameters.to = [ "cm: email"];
            mail.parameters.subject = "Notice of assignment;
            mail.parameters.from = "noreply@edu.gva.es";
            mail.parameters.text = acl + "Do not respond to this mensaje.Tiene an assignment should review http://notasinternas.edu.gva.es here";
            mail.execute (bpm_package);

</ script>
</ action>
</ event>
         <transition name="reject" to="endreview" />
         <transition name="approve" to="endreview">
             <script>
                 <variable name="wf_approveCount" access="read,write" />
                 <expression>
                     wf_approveCount = wf_approveCount +1;
                  </ expression>
             </ script>
         </ transition>
     </ task-node>

     <join name="endreview">
         <transition to="isapproved" />
     </ join>

     <decision name="isapproved">
         <event type="node-enter">
            <script>
               <variable name="wf_reviewerCount" access="write"/>
               <variable name="wf_requiredPercent" access="write"/>
               <variable name="wf_actualPercent" access="write"/>
               <expression>
                   wf_requiredPercent = wf_requiredApprovePercent;
                   wf_reviewerCount = bpm_assignees.size ();
                   wf_actualPercent = ((wf_approveCount * 100) / wf_reviewerCount);
               </ expression>
            </ script>
         </ event>
         <transition name="reject" to="rejected" />
         <transition name="approve" to="approved">
             <condition> # (wf_actualPercent> = wf_requiredApprovePercent) </ condition>
         </ transition>
     </ decision>
               
     <task-node name="rejected">
         <transition to="end" />
     </ task-node>

     <task-node name="approved">
         <transition to="end" />
     </ task-node>

     <end-state name="end"/>

</ process-definition>

jpotts
World-Class Innovator
World-Class Innovator
I'm not entirely following what you're trying to do here or what the problem is. But it sounds like you have one process that successfully changes the permissions and another one that doesn't. It also sounds like the second process might be triggered by something. So I'm wondering if maybe the second process doesn't have a user context that has enough privileges to change the permissions. Have you tried using the "<runas>" element to execute your workflow JavaScript as admin?

Jeff