cancel
Showing results for 
Search instead for 
Did you mean: 

How do I read the Task ID

brentkastner
Champ in-the-making
Champ in-the-making
Hi folks,

I have written a workflow that sends email to reviewers along with actionable links.  The email is being sent fine, but I can't seem to extract the taskid from workflow process variables.  Here is an example of my code

mail.parameters.text = "Please review and if you like the changes, approve this task.  You can click here http://localhost:8080/alfresco/command/task/end/jbpm$" + bpm_taskId + "/approve to instantly approve.";

You will note the bpm_taskId variable.  This does not work.  I have tried many iterations and other variables but can't seem to find the task ID.  Other variables work fine in this block (such as workflowDescription, initiator, etc).  Does anyone know the variable name for the taskid?  Or where this might be documented?  The wiki does not have the information I need.

Brent Kastner
6 REPLIES 6

brentkastner
Champ in-the-making
Champ in-the-making
This is the dump from the workflow console.

id: jbpm$87
name: wcmwf:reviewTask
title: Review
description: Review Documents to approve or reject them
state: IN_PROGRESS
path: jbpm$43-@review.0
transitions: 2
transition: reject , title: reject , desc: reject
transition: approve , title: approve , desc: approve
properties: 20
{http://www.alfresco.org/model/bpm/1.0}dueDate = null
{http://www.alfresco.org/model/bpm/1.0}context = null
{http://www.alfresco.org/model/bpm/1.0}description = fds
{http://www.alfresco.org/model/bpm/1.0}pooledActors = []
{http://www.alfresco.org/model/content/1.0}created = 2007-03-15 11:07:02.0
{http://www.alfresco.org/model/bpm/1.0}outcome = EmailNotification
{http://www.alfresco.org/model/bpm/1.0}completionDate = null
{http://www.alfresco.org/model/bpm/1.0}status = Not Yet Started
{http://www.alfresco.org/model/wcmworkflow/1.0}reviewType = Parallel
{http://www.alfresco.org/model/wcmworkflow/1.0}fromPath = alfresco–admin:/www
{http://www.alfresco.org/model/content/1.0}owner = admin
{http://www.alfresco.org/model/bpm/1.0}packageActionGroup =
{http://www.alfresco.org/model/bpm/1.0}assignees = [workspace://SpacesStore/4ff9de26-d27a-11db-8e7c-9f6ea315720d]
{http://www.alfresco.org/model/bpm/1.0}priority = 3
{http://www.alfresco.org/model/bpm/1.0}startDate = null
{http://www.alfresco.org/model/wcmworkflow/1.0}label = fds
{http://www.alfresco.org/model/bpm/1.0}percentComplete = 0
{http://www.alfresco.org/model/bpm/1.0}taskId = 87
{http://www.alfresco.org/model/bpm/1.0}package = avm://alfresco–workflow-34f5dd65-d30f-11db-adab-4b59abb3e52b/-1;www
{http://www.alfresco.org/model/bpm/1.0}packageItemActionGroup = edit_wcm_package_item_actions

All I am looking for is the variable name for either id, or taskId.

Brent

brentkastner
Champ in-the-making
Champ in-the-making
taskInstance.id - not in the documentation, just from hacking around Smiley Happy.

brent

coffman
Champ in-the-making
Champ in-the-making
Hi.
I have the same problem.

I can't read de taskId, but i can't read the taskInstance.id too.

So i can't imagine how to know the task Id on a node of the processdefinition.

I am using Alfresco Enterprise 2.1

Thanks

tbillard
Champ in-the-making
Champ in-the-making
Hi lads,

I get the solution to solve your problem :

If you wanna send a mail with a link to the manage task you can do it like this.

      <task-node name="reviewX">
         <event type="task-create">
         <script>
            <variable name="myTaskId" access="read,write" />
             <expression>myTaskId = "jbpm$"+ executionContext.getTaskInstance().getId();</expression>
            </script>
          <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
             <script>
               <!–  create mail action–>
               var mail = actions.create("mail");
               var mydoc=bpm_package.children[0];
                 var gpeSender = new Array();
               gpeSender[0]="GROUP_Y";          
               mail.parameters.to_many = gpeSender;
               mail.parameters.subject = "[SG]Un document est à valider";
               mail.parameters.from = "alfresco@knowings.com";
                  var myTemplate=companyhome.childByNamePath("Dictionnaire des Données/Modèles d'Emails/workflow/newTask_workflow_mail.ftl");
               var args = new Array();
               args["id"]=myTaskId;
               args["type"]="reviewX";
               mail.parameters.text = mydoc.processTemplate(myTemplate,args);
               <!– execute action against a document–>   
               mail.execute(bpm_package);
                 </script>
            </action>       
       </event>
      
          <task name="mytask1" swimlane="myswimlane" />   
        <transition name="approve" to="reviewY"></transition>
           <transition name="reject" to="revise"></transition>
     </task-node>

Note that you have to pick-up the TaskId in the event-type "task-create" otherwise it will not work at all.

You'll also find in the code the way to pass the task-id to the content of the mail. This is done by calling the method process-template() with args.

Hopes it will help you  Smiley Happy

Regards,

Thomas
Company KNOWINGS (Alfresco partner)

chicco0386
Champ on-the-rise
Champ on-the-rise
Hi,
I'm interested to this topic why I want to send an email from template, and pass to this template some params.
I try the code that you've posted, but I can't read the args parameter inside the template.
This is my node inside the WF that send the mail:
<start-state name="Start">
      <task name="wfTria:inizio" swimlane="initiator"></task>
      <event type="node-leave">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
            <script>
               try {
                  var mail = actions.create("mail");
                  <!– mail.parameters.from = initiator.properties.email; –>
                  mail.parameters.to = "enrico_zeranto@mytria.it";
                  mail.parameters.subject = "[Afresco] Ti è stato assegnato un workflow";
                  <!– Creazione template –>
                  var myTemplate=companyhome.childByNamePath("Data Dictionary/Email Templates/wf_invitation.ftl");
                  var args = new Array();
                                                args["wf_name"]="Opportunity";
                                        mail.parameters.text = bpm_package.children[0].processTemplate(myTemplate,args);
                     
                  <!– Testo del messaggio alternativo al template, nel caso in cui non venga trovato –>
                  mail.parameters.text = initiator.properties.firstName + " "
                  + initiator.properties.lastName + " ti ha assegnato un workflow.
                  \u000D\u000D" + "Accedi alla console Alfresco per visualizzare i task
                  a te assegnati";
                  mail.execute(bpm_package);
                  
               } catch (e){
                  logger.log("node [Start], error durante l'invio della mail di segnalazione di attivazione WF." + e);
               }
              </script>
         </action>
      </event>
      <transition to="Decidi numero e nome progetto"></transition>
   </start-state>

And this the tempalte:
Sei stato assegnato ad un workflow.

<#– Accedi alla console Alfresco (${url.serverPath}${url.context}) per visualizzare i task a te assegnati. –>

<#assign keys = args?keys>
<#list keys as arg>     
   ${arg}
</#list> 

And the mail is not send.

Can you help me or post your template that read args params?

Thank you

chicco0386
Champ on-the-rise
Champ on-the-rise
Hi,
I'm interested to this topic why I want to send an email from template, and pass to this template some params.
I try the code that you've posted, but I can't read the args parameter inside the template.
This is my node inside the WF that send the mail:
<start-state name="Start">
      <task name="wfTria:inizio" swimlane="initiator"></task>
      <event type="node-leave">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
            <script>
               try {
                  var mail = actions.create("mail");
                  <!– mail.parameters.from = initiator.properties.email; –>
                  mail.parameters.to = "enrico_zeranto@mytria.it";
                  mail.parameters.subject = "[Afresco] Ti è stato assegnato un workflow";
                  <!– Creazione template –>
                  var myTemplate=companyhome.childByNamePath("Data Dictionary/Email Templates/wf_invitation.ftl");
                  var args = new Array();
                                                args["wf_name"]="Opportunity";
                                        mail.parameters.text = bpm_package.children[0].processTemplate(myTemplate,args);
                     
                  <!– Testo del messaggio alternativo al template, nel caso in cui non venga trovato –>
                  mail.parameters.text = initiator.properties.firstName + " "
                  + initiator.properties.lastName + " ti ha assegnato un workflow.
                  \u000D\u000D" + "Accedi alla console Alfresco per visualizzare i task
                  a te assegnati";
                  mail.execute(bpm_package);
                  
               } catch (e){
                  logger.log("node [Start], error durante l'invio della mail di segnalazione di attivazione WF." + e);
               }
              </script>
         </action>
      </event>
      <transition to="Decidi numero e nome progetto"></transition>
   </start-state>

And this the tempalte:
Sei stato assegnato ad un workflow.

<#– Accedi alla console Alfresco (${url.serverPath}${url.context}) per visualizzare i task a te assegnati. –>

<#assign keys = args?keys>
<#list keys as arg>     
   ${arg}
</#list> 

And the mail is not send.

Can you help me or post your template that read args params?

Thank you

I've solved, I rewrite the emai.text after the generate template… Smiley Surprisedops:  Smiley Tongue