cancel
Showing results for 
Search instead for 
Did you mean: 

Send email from workflow

cloisel
Champ in-the-making
Champ in-the-making
Hi everyone,

I know it's been already asked before, but I can't get it working with any solutions provided on this forum…
I'm trying to send an email from a workflow with no success. I successfully managed to make it work as a webscript:

xxx.get.js:

var node = person;
var mail = actions.create("mail");
mail.parameters.to = node.properties.email;
mail.parameters.subject = "TEST Send Mail Webscript";
mail.parameters.text = "test webscript";
mail.execute(node);

I managed the outgoing mail setup and it works fine.

Here is my AlfrescoJS (workflow):


var mail = actions.create("mail");
mail.parameters.to = initiator.properties.email;
mail.parameters.subject = "TEST Send Mail Workflow";
mail.parameters.text = "test workflow";
var node = bpm_package.children[0];
mail.execute(node);

In examples, I find 2 different syntaxes:

var node = bpm_package;
and

var node = bpm_package.children[0];

Which one is the right one? Depends on what?

Thanks in advance for any reply or ideas?
2 REPLIES 2

zaizi
Champ in-the-making
Champ in-the-making
Post your workflow definition please.

cloisel
Champ in-the-making
Champ in-the-making
Here is the processDefinition.xml:


<?xml version="1.0" encoding="iso-8859-1"?>

<process-definition name="wfbxlicenseQuery:licenseQuery">

     <swimlane name="manager">
           <assignment actor-id="manager"/>
           
           <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
              <pooledactors>#{people.getGroup('GROUP_manager')}</pooledactors>              
           </assignment>  
     </swimlane>
     <swimlane name="admin">
     </swimlane>

     <start-state name="start">
        <task name="wfbxlicenseQuery:start">
        </task>

        
        <transition name="goAskEvaluationKey" to="decisionTypeEvaluationKey">
              <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                     <variable name="bpm_package" access="read"/>
                  <expression>
                  //Test
                  var node = bpm_package.children[0];
                  node.properties['cm:name']; = "newpack";
                  node.save();
                  </expression>
               </script>
            </action>

        </transition>
     </start-state>

   <end-state name="keyQueryPrototypeFinishedValidated"/>
   <end-state name="keyQueryPrototypeFinishedUnvalidated"/>
   <end-state name="keyQuerySIDEFinishedUnvalidated"/>
   <end-state name="keyQuerySIDEFinishedValidatedShort"/>
   <end-state name="keyQuerySIDEFinishedValidatedLong"/>

   <task-node name="validateKeyQueryPrototype">
      <task name="wfbxlicenseQuery:validateKeyQueryPrototype" swimlane="manager">

        </task>

        
        <transition name="goDecideGenerateKeyPrototype" to="decisionGenerateKeyPrototype">
              <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  <expression>
                  // Get number of key queries for the user
                  </expression>
               </script>
            </action>

        </transition>
   </task-node>
   <task-node name="validateKeyQuerySIDE">
      <task name="wfbxlicenseQuery:validateKeyQuerySIDE" swimlane="manager">

        </task>

        
        <transition name="goDecideGenerateKeySIDE" to="decisionGenerateKeySIDE">

        </transition>
   </task-node>





   <decision name="decisionTypeEvaluationKey">
        
      <transition name="validateKeyQuerySIDE" to="validateKeyQuerySIDE">
        <condition>#{wfbxlicenseQuery_typeEvaluationKey=='SIDE/Alfresco'}</condition>
        </transition>
        
      <transition name="validateKeyQueryPrototype" to="validateKeyQueryPrototype">
        </transition>
   </decision>
   <decision name="decisionGenerateKeyPrototype">
        
      <transition name="keyQueryPrototypeFinishedValidated" to="keyQueryPrototypeFinishedValidated">
              <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  <expression>
                  //Generate Key
                  // +
                  //Send mail to user containing key + infos
                  // +
                  //Send mail to admin containing infos
                  // +
                  //Create node contact
                  // +
                  //Create node license Prototype
                  //
                  var mail = actions.create("mail");
                  mail.parameters.to = initiator.properties.email;
                  mail.parameters.subject = "TEST Send Mail Workflow Prototype OK";
                  mail.parameters.text = "test workflow";
                  mail.execute(bpm_package);
                  </expression>
               </script>
            </action>
        <condition>#{wfbxlicenseQuery_validatedKeyQueryPrototype=='Yes'}</condition>
        </transition>
        
      <transition name="keyQueryPrototypeFinishedUnvalidated" to="keyQueryPrototypeFinishedUnvalidated">
              <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  <expression>
                  //Send mail to user for unvalidating the key query + infos
                  // +
                  //Send mail to manager containing infos
                  
                  var mail = actions.create("mail");
                  mail.parameters.to = initiator.properties.email;
                  mail.parameters.subject = "TEST Send Mail Workflow Prototype KO";
                  mail.parameters.text = "test workflow";
                  mail.execute(bpm_package);
                  </expression>
               </script>
            </action>
        </transition>
   </decision>
   <decision name="decisionGenerateKeySIDE">
        
      <transition name="decisionDependsNumberQuery" to="decisionDependsNumberQuery">
              <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  <expression>
                  // Get number of key queries for the user
                  </expression>
               </script>
            </action>
        <condition>#{wfbxlicenseQuery_validatedKeyQuerySIDE=='Yes'}</condition>
        </transition>
        
      <transition name="keyQuerySIDEFinishedUnvalidated" to="keyQuerySIDEFinishedUnvalidated">
              <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  <expression>
                  // Send mail to user for unvalidating the key query + infos
                  // +
                  //Send mail to manager containing infos
                  // +
                  // Update number of key queries
                  
                  var mail = actions.create("mail");
                  mail.parameters.to = initiator.properties.email;
                  mail.parameters.subject = "TEST Send Mail Workflow SIDE/Alfresco KO";
                  mail.parameters.text = "test workflow";
                  mail.execute(bpm_package);
                  </expression>
               </script>
            </action>
        </transition>
   </decision>
   <decision name="decisionDependsNumberQuery">
        
      <transition name="keyQuerySIDEFinishedValidatedShort" to="keyQuerySIDEFinishedValidatedShort">
              <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  <expression>
                  //Generate Key for 15 days
                  // +
                  //Send mail to user containing key + infos
                  // +
                  //Send mail to manager containing infos
                  // +
                  //Retrieve user from contact list
                  // +
                  //Update number of key queries
                  
                  var mail = actions.create("mail");
                  mail.parameters.to = initiator.properties.email;
                  mail.parameters.subject = "TEST Send Mail Workflow SIDE/Alfresco OK short";
                  mail.parameters.text = "test workflow";
                  mail.execute(bpm_package);
                  </expression>
               </script>
            </action>
        <condition>#{wfbxlicenseQuery_numberQuery&lt;=2}</condition>
        </transition>
        
      <transition name="keyQuerySIDEFinishedValidatedLong" to="keyQuerySIDEFinishedValidatedLong">
              <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  <expression>
                  //Generate temporary key for 3 days
                  // +
                  //Generate key for 31 days
                  // +
                  //Send mail to user containing temporary key + infos
                  // +
                  //Send mail to manager containing infos (both keys)
                  // +
                  //Retrieve user from contact list
                  // +
                  //Update number of key queries
                  
                  var mail = actions.create("mail");
                  mail.parameters.to = initiator.properties.email;
                  mail.parameters.subject = "TEST Send Mail Workflow SIDE/Alfresco OK long";
                  mail.parameters.text = "test workflow";
                  mail.execute(bpm_package);
                  </expression>
               </script>
            </action>
        </transition>
   </decision>


</process-definition>


The same script part has been used several times in the process definition (each time the same way).

I took example on adhoc task. Does it work? Because I tried to notify an user with no success. I succeeded in sending mails anyway through webscripts.

Any ideas?

I'm using Alfresco 3.2 r2.

Thanks in advance