cancel
Showing results for 
Search instead for 
Did you mean: 

How to find current workflow user? [SOLVED]

jimcornmell
Champ in-the-making
Champ in-the-making
Hi All,

Again help in advance.

Within my process definition I have the following task.  In it I'm trying to find the current user who kicks of the "Send to Artist" transition.

<task-node name="Waiting for Artist">
   <task name="wf:waitingForArtistTask" swimlane="artistsPool" />
   <transition name="Send to Artist" to="Create">
      <script>
         <variable name="wf_reader" access="write" />
         <variable name="bpm_assignee" access="read" />
         <expression>
            wf_reader = "New reader = " + bpm_assignee;
         </expression>
      </script>
   </transition>
</task-node>

I've tried the above but I get null for bpm_assignee.  I've deliberately ignored initiator although I get a value for this the wiki states this is "the person who initiated the workflow", and I don't need that information.

My question is: Which variable do I need to access to find the current user?

Jim
4 REPLIES 4

rob562435
Champ in-the-making
Champ in-the-making
YOu could use the "variable" person to access the current user performing an action!
For instance:
person.properties.userName
would return the user name of the current user.
In your case you have probably add also
<variable name="person" access="read"/>
to your script.

Good luck. Rob

jimcornmell
Champ in-the-making
Champ in-the-making
Hi rob,

I've tried the following:

<task-node name="Waiting for Artist">
   <task name="wf:waitingForArtistTask" swimlane="artistsPool" />
   <transition name="Send to Artist" to="Create">
      <script>
         <variable name="wf_reader" access="read,write" />
         <variable name="person" access="read" />
         <expression>
            wf_reader = "new reader = " + person.properties.userName;
         </expression>
      </script>
   </transition>
</task-node>

But all I get is a null pointer exception.  Looking more closely person is null.  Do I need to add this to my aspect?  Or how do I inherit it?

Jim

rob562435
Champ in-the-making
Champ in-the-making
Hi Jim,

I think the problem is that you are using "Java" and not "JavaScript"

Here is an example of some code I use:
  <transition name="Continue" to="createCcr">
   <condition>#{!qcp_wfIssueExist}</condition>
   <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
    <script>
     var logDateTime = new Date();
     var ccrLogFile = companyhome.childByNamePath("CCR repository/Log files/" + qcp_wfCcrNr + ".log");
     if (ccrLogFile != null)
     {
      var logLine = logDateTime.getFullYear() + ";" + utils.pad(logDateTime.getMonth()+1,2) + ";" + utils.pad(logDateTime.getDate(),2);
      logLine += ";" + utils.pad(logDateTime.getHours(),2) + ";" + utils.pad(logDateTime.getMinutes(),2) + ";" + utils.pad(logDateTime.getSeconds(),2);
      logLine += ";" + utils.pad(logDateTime.getTime(),16);
      logLine += ";" + qcp_wfCcrNr;
      logLine += ";" + person.properties.userName + ";" + "" + ";" + qcp_wfCycleNr;
      logLine += ";" + "Issue number checked and found unique";
      logLine += ";" + bpm_package.children[0].properties["qcp:previousWorkflowStatus"];
      logLine += ";" + bpm_package.children[0].properties["qcp:currentWorkflowStatus"];
      ccrLogFile.content += logLine + "\r\n";
     }
     bpm_package.children[0].properties["qcp:previousWorkflowStatus"] = "qcp:mayCreateCcr";
     bpm_package.children[0].save();
     if (bpm_package.children.length &gt; 1)
      for (var i = 1; i &lt; bpm_package.children.length; i++)
       if (bpm_package.children[i].parent.properties.name != bpm_package.children[0].parent.properties.name)
       {
        var newCopy = bpm_package.children[i].copy(bpm_package.children[0].parent);
        bpm_package.removeNode(bpm_package.children[i]);
        bpm_package.addNode(newCopy);
       }
    </script>
   </action>
  </transition>
So you might try to add
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
and
</action>
around your script.
As you can see I did not use the
<variable
and
<expression
tags but that would not be the problem I guess.

Success,
Regards, Rob

jimcornmell
Champ in-the-making
Champ in-the-making
SOLVED: MANY MANY thanks rob, I just needed the right combination.  The following works.  It has a bit of a red herring because the various error messages did not relate to their being a problem with the tagging….

<task-node name="Waiting for Artist">
   <task name="wf:waitingForArtistTask" swimlane="artistsPool" />
   <transition name="Send to Artist" to="Create">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
            <variable name="wf_reader" access="read,write" />
            <expression>
               wf_reader = person.properties.userName;
            </expression>
         </script>
      </action>
   </transition>
</task-node>