cancel
Showing results for 
Search instead for 
Did you mean: 

Mail Task

joshjones
Champ in-the-making
Champ in-the-making
Hi,

In my workflow I am looking to use mail tasks as part of the process. However the recipient of the mail will differ from time to time. Can you use the "To" field in a more general sense or do you have to specify the exact recipient for each task.

Thanks.
8 REPLIES 8

darkredd
Star Contributor
Star Contributor
Hi Jones,

Place a variable in the "To" field which you can then manipulate in each task.

joshjones
Champ in-the-making
Champ in-the-making
Hi DarkRedd,

Can you provide me with a link or something that would give me more details about how to use variables?

Thanks

darkredd
Star Contributor
Star Contributor
You can declare and set a variable anywhere in you definition, say like this:
var mail_recipient = bpm_assignee.properties.email; 
and then reference it like this in your mail task:
${mail_recipient}


Hope this helps.

joshjones
Champ in-the-making
Champ in-the-making
I cannot seem to declare the variable in the definition. I also tried ${bpm_assignee.properties.email} within the 'To' field. Am I meant to declare the variable in the bpmn file or somewhere else entirely different?

Post your bpm file here so we can have a look at it.

Post your bpm file here so we can have a look at it.

joshjones
Champ in-the-making
Champ in-the-making
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="localReview" name="Local Review" isExecutable="true">
    <startEvent id="startEvent" name="Start" activiti:formKey="wf:newCaseReview"></startEvent>
    <serviceTask id="mailArea" name="Mail AC" activiti:type="mail">
      <extensionElements>
        <activiti:field name="to">
          <activiti:expression>${bpm_assignee.properties.email}</activiti:expression>
        </activiti:field>
        <activiti:field name="text">
          <activiti:string><![CDATA[A new case is up for local review. Please follow the link below to view the case.]]></activiti:string>
        </activiti:field>
        <activiti:field name="subject">
          <activiti:string><![CDATA[New Case up for Review]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <userTask id="gatherEvidence" name="AC gather evidence" activiti:assignee="${bpm_assignee.properties.userName}"></userTask>
    <sequenceFlow id="flow4" sourceRef="mailArea" targetRef="gatherEvidence"></sequenceFlow>
    <userTask id="lReview" name="Local Review" activiti:assignee="${bpm_assignee.properties.userName}"></userTask>
    <userTask id="archive" name="Archive Case" activiti:assignee="${bpm_assignee.properties.userName}"></userTask>
    <sequenceFlow id="flow8" sourceRef="lReview" targetRef="archive"></sequenceFlow>
    <serviceTask id="mailReviewers" name="Mail Reviewers" activiti:type="mail">
      <extensionElements>
        <activiti:field name="to">
          <activiti:expression>${bpm_assignee.properties.email}</activiti:expression>
        </activiti:field>
        <activiti:field name="text">
          <activiti:string><![CDATA[hello]]></activiti:string>
        </activiti:field>
        <activiti:field name="subject">
          <activiti:string><![CDATA[Please Review Case]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <sequenceFlow id="flow17" sourceRef="mailReviewers" targetRef="lReview"></sequenceFlow>
    <sequenceFlow id="flow18" sourceRef="startEvent" targetRef="mailArea"></sequenceFlow>
    <sequenceFlow id="flow19" sourceRef="gatherEvidence" targetRef="mailReviewers"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow20" sourceRef="archive" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_localReview">
    <bpmndi:BPMNPlane bpmnElement="localReview" id="BPMNPlane_localReview">
      <bpmndi:BPMNShape bpmnElement="startEvent" id="BPMNShape_startEvent">
        <omgdc:Bounds height="35.0" width="35.0" x="240.0" y="109.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="mailArea" id="BPMNShape_mailArea">
        <omgdc:Bounds height="55.0" width="105.0" x="365.0" y="99.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="gatherEvidence" id="BPMNShape_gatherEvidence">
        <omgdc:Bounds height="55.0" width="105.0" x="515.0" y="99.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="lReview" id="BPMNShape_lReview">
        <omgdc:Bounds height="55.0" width="105.0" x="655.0" y="255.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="archive" id="BPMNShape_archive">
        <omgdc:Bounds height="55.0" width="105.0" x="791.0" y="255.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="mailReviewers" id="BPMNShape_mailReviewers">
        <omgdc:Bounds height="55.0" width="105.0" x="515.0" y="255.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="826.0" y="350.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="470.0" y="126.0"></omgdi:waypoint>
        <omgdi:waypoint x="515.0" y="126.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
        <omgdi:waypoint x="760.0" y="282.0"></omgdi:waypoint>
        <omgdi:waypoint x="791.0" y="282.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow17" id="BPMNEdge_flow17">
        <omgdi:waypoint x="620.0" y="282.0"></omgdi:waypoint>
        <omgdi:waypoint x="655.0" y="282.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow18" id="BPMNEdge_flow18">
        <omgdi:waypoint x="275.0" y="126.0"></omgdi:waypoint>
        <omgdi:waypoint x="365.0" y="126.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow19" id="BPMNEdge_flow19">
        <omgdi:waypoint x="567.0" y="154.0"></omgdi:waypoint>
        <omgdi:waypoint x="567.0" y="255.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow20" id="BPMNEdge_flow20">
        <omgdi:waypoint x="843.0" y="310.0"></omgdi:waypoint>
        <omgdi:waypoint x="843.0" y="350.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

darkredd
Star Contributor
Star Contributor
Hi Josh,

According to this post I have read, if you are using the Activiti engine bundled with Alfresco; your mail task will not work. Instead use a service/script task and invoke the mail action within that script. Here is the link: https://forums.alfresco.com/forum/developer-discussions/workflow/sendmail-activiti-not-working-03192...

Hope this helps.