cancel
Showing results for 
Search instead for 
Did you mean: 

How to get current username in javascript using script task?

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

I'm trying to get the currently logged username in a script task to put it in a variable that I call in a REST call task but I don't know how to do this and i can't find any documentation on how to do this in Javascript

I don't want to use java-code (I don't know where to put the java.class files)

Thanks in advance
20 REPLIES 20

hari
Star Contributor
Star Contributor
Hi,

I dont think you can get the currently logged in user name in a script task. Reason being, its not dependent on any user to get executed nor it depends on a specific UI framework.  But you can always assign the task to users at runtime by having assignee set to ${myuser} and by passing or setting the value of myuser(this is my sample variable. you can always use a different one) at runtime.

> I don't want to use java-code (I don't know where to put the java.class files)
You can bundle up all your java files into a jar and have the jar in the class path.

madn
Champ in-the-making
Champ in-the-making
What do you mean about " have the jar in the class path?"

I'm seeing there's a lot of xxxx.jar files in C:\Activiti\tomcat\lib and in C:\Activiti\java\lib

Am I supposed to put my .jar in one of these directory ?

And what am I supposed to do to get the current logged userId using java ?

madn
Champ in-the-making
Champ in-the-making
I can't do your first proposal because I need to connect on my Alfresco One using the secret and the userName to get a ticket from Alfresco and i want my processe to be accessible and usable by any user that are authorized

madn
Champ in-the-making
Champ in-the-making
I heard about a variable called INITIATOR, can i call it in a script task ?

I dont know the correct syntax .

hari
Star Contributor
Star Contributor
Hi,

If you want to assign it to initiatior, try this $INITIATOR
but initiator is not the logged in user. its the one who started the process.

And regarding the jar file. It needs to be in the class path. If you are using tomcat, you can have it in tomcat's lib folder.

madn
Champ in-the-making
Champ in-the-making
This isn't working, here's my bpmn20.xml code

what's wrong ?

madn
Champ in-the-making
Champ in-the-making
Do you know the answer ?

vasile_dirla
Star Contributor
Star Contributor
$INITIATOR will store the id of the user who initiated the process.
and in order to get this value you should use:
<code>
var myInitiator = execution.getVariable("$INITIATOR");
</code>

In my opinion you better use a ServiceTask with a JavaDelegate.
and in this case your code will be like that:
<code>

User currentUser = SecurityUtils.getCurrentUserObject();
if (currentUser != null){
execution.setVariable("userEmailAddress", currentUser.getEmail());
}
</code>

madn
Champ in-the-making
Champ in-the-making
I put var myInitiator = execution.getVariable("$INITIATOR");
in my script task and this is returning me "(empty)"