cancel
Showing results for 
Search instead for 
Did you mean: 

How to get username of the person to execute a task

xena
Champ in-the-making
Champ in-the-making
Hello!
I created an advanced workflow in which the approval task is assigned to the group "approvers" who are the Project Manager.
I also created an aspect "utente" that should show the username of the project manager who has taken over the task of approval. How can I do?
This is the code:
<swimlane name="approvers">
           <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
                  <pooledactors>#{people.getGroup('GROUP_ProjectManager')}
      </pooledactors>
   </assignment>
   </swimlane>


<task-node name="Validazione">
   <event type="node-enter">
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <runas>admin</runas>
               <script>
                   for (var i = 0; i &lt; bpm_package.children.length; i++)
                   {
                      bpm_package.children[i].properties["wfpm:status"] = "Verificato";
                      bpm_package.children[i].save();
                   }
               </script>
           </action>
       </event>
         <event type="node-leave">
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
             <runas>admin</runas>
               <script>
                   for (var i = 0; i &lt; bpm_package.children.length; i++)
                   {
                          if (!bpm_package.children[i].hasAspect("wfpm:utente"))
                      {
                         bpm_package.children[i].addAspect("wfpm:utente");
                      }
                   }
                    </script>
           </action>
       </event>
      <transition to="Rifiutato" name="Rifiuta"></transition>
      <transition to="Validato" name="Valida"></transition>
         <task name="wfpm:validazioneTask" swimlane="approvers" />
   </task-node>

<task-node name="Validato">
     <event type="node-enter">
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <runas>admin</runas>
                <script>
                   //first proof
                   //var utente=people.getPerson(people.getGroup('GROUP_ProjectManager'))).properties.userName;

                    //second proof
                        var utente=people.getPerson(approvers).properties.userName;


                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                   {
                       bpm_package.children[i].properties["wfpm:utente"] = utente;
                      bpm_package.children[i].properties["wfpm:status"] = "Validato";
                      bpm_package.children[i].save();
                   }
                </script>
           </action>
       </event>
   <task name="wfpm:ValidatoTask" swimlane="initiator" />
<transition to="End" name="termina"></transition>
</task-node>
During the validation task, when I click , the button "Valida"
In the first case gives me the error: TypeError: Can not read property "properties" from null (AlfrescoJS # 1)
In the second case the error is: ReferenceError: "approvers" is not defined. (AlfrescoJS # 1)
Any suggestions??
5 REPLIES 5

giorgio
Champ in-the-making
Champ in-the-making
Hi Xena

if I remember correctly with this line

bpm_package.children . properties ["wfpm: status"] = "Verificato"

what you are doing is assigning a value to a property status
you have a file associated with the particular workflow as you have within
of for, really you're doing to all documents associated with having the workflow, I guess you do not have any document associated with it?
why it is coming out the error you property, try to attach a workflow document that has a property defined as wfpm: status

if what you are trying to access is a property of how to access workflow is bpm_package.properties [wfpm: status], children are for documents related to workflow, but should be a defined value for this property. Check the wiki to document yourself about this because long ago I do not play and what the story is how little I remember.

A greeting.

xena
Champ in-the-making
Champ in-the-making
Viewing the many forums and trying all the possible solutions I finally found the right version.
As I am finally able to get the variable that corresponds to the user that execute the task, in the end I have got directly the first and last name, no more the username.
This is the code:

<task-node name="Validazione" >
     <task name="wfpm:validazioneTask" swimlane="approvers" >
  <event type="task-end">
               <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                  <script>
                     <variable name="bpm_assignee" access="write"/>
                     <expression>
                        if (taskInstance.actorId != null)
                           people.getPerson(taskInstance.actorId);
                        else
                           person;
                     </expression>
                  </script>
                </action>
            </event>
        </task>

       <event type="node-enter">
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <runas>admin</runas>
               <script>
                   for (var i = 0; i &lt; bpm_package.children.length; i++)
                   {
                      bpm_package.children[i].properties["wfpm:status"] = "Verificato";
                      bpm_package.children[i].save();
                   }

               </script>
           </action>
       </event>
      <transition to="Rifiutato" name="Rifiuta"></transition>
      <transition to="Validato" name="Valida">
                 <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <runas>admin</runas>
               <script>
                   for (var i = 0; i &lt; bpm_package.children.length; i++)
                   {
                       var nome= bpm_assignee.properties["cm:firstName"];
                       var cognome=  bpm_assignee.properties["cm:lastName"];
                       var utente= nome + ' ' + cognome;
                       bpm_package.children[i].properties["wfpm:utente"] = utente;

                       bpm_package.children[i].save();
                   }

               </script>
           </action></transition>
   </task-node>
I think the main point where was wrong was that I wanted to call the variable in the node-enter, but now declaring the variable bmp_assignee in the task-end event, and taking one of its properties during the transition, (not in the next task-node ), I finally get what I needed
Smiley Happy

giorgio
Champ in-the-making
Champ in-the-making
But with this lines :

bpm_package.children.properties["wfpm:status"] = "Verificato";
                      bpm_package.children.save();


you set the property on the workflow or on the associated files in the workflow?

could you remember me?

xena
Champ in-the-making
Champ in-the-making
Hi giorgio!
With that code I set the custom property "status" that I have created for files that are included in the workflow.

giorgio
Champ in-the-making
Champ in-the-making
aha, ok, I thought. Thank you very much.

greetings.