how to check currently logged in user of JIRA in velocity template ?


I have developed JIRA custom field plugin(type : text) and i want it to be visible only for particular user .

How to check currently logged in user of JIRA in velocity template ?

Do i need to fetch loggedin user in my java file and then assign to varaible then it can be accessible to vm file

5 answers

1 accepted

7 votes
Accepted answer

you can try with $

or using javascript you can get current loggedin user details

try with this inside javascript,


try with this idf you want check current user in specific group


check this, it may help you

if something helped then don't forgot to accept as a answer it will help to other users to choose right answer!!

Hi ,

Thanks lot :)

I ll explain my scenario :

I have developed one custom field plugin , wanted to display only for the user who belong to particular group.

I have used the below line of code in my edit.vm file and built a jar deployed in jira using admin role , then created new custom field using that JAR addedd to particular project and to the screen which the project is using.

After logeg in to jira as normal user still i'm not able to view that field when creating issue.

Could you pls help me

#if (${jiraUserUtils.getGroupNamesForUser($'Jira-users')})
<input type="text" name="$" value="$value" id="$" class="text"/>
<input type="text" name="$" value="" id="$" class="text"/>

Still it is hidden only . Even if user in 'jira-user' group not able to view when creating issue .

which version of jira you are using?

I m using Jira v 5.0.

can you confirm what is the group name you used

jira-users or Jira-users ? check the first leter, it should be small leter

Hi rambanam ,

great !!!!!! it's working fine. thanks a lot .

and one more doubt. field name should also be hidden . is it possible? because custom field name being created when creating new custom field

Glad to hear it worked!!

where needs to hidden the field name?

In screen i want to hide label name of the custom field. (ex : when creating issue)

Hi ,

Is there any document where i could find how to use objects from JIRA-API class in velocity template?

For "jiraUserUtils" which is being used in velocity template. i am not able find any API document for further reference

hi @rambanam prasad

Thanks for your immmediate respone for my queries .

In the above link i coudn't find "jiraUserUtils" object .The only thing i could see the object for velocity template in this link, but i want to know how the objects can be used in velocity template

EX : ${jiraUserUtils.getGroupNamesForUser($'jira-users')}

In the above example "$authcontext" object is used to find logged in user and i have checked the corresponding API class in the below link:

Here i couldn't find "loggedInUser" method instead "getLoggedInUser" is available anyhow i considered that "getLoggedInUser" can also be called as "$authcontext.loggedInUser" ,but "name" is not available in that class.

from where it's being called.

Could you please explain ?

hi @rambanam prasad

Actually the field is displaying based on the user group but i also want to hide label name for the field . how to hide it ?

i am not much expertise in velocity files, i suggest gothrough the following document

you can find the "jiraUserUtils" Object here i think you can use UserUtils Object also to get user details

"$authcontext.loggedInUser" will return the User Object in that getName() method is there so use the "$"

How to hide label:

where you have declared label for your field?

@rambanam prasad

Actually i have build custom field jira plugin where it is visible only for "jira-users"

group .then i have uploaded to "Universal plugin manager" in JIRA

When creating new custom field ,Name for the field must be set and assigned that filed to screen which is used in "X" project.

when creating issue , field input box displaying to the user who belong to the "Jira-users" group, but when the other user creating the issue at that time filed is hidden but the name for the field is still displaying which has been set when the custom field is created.

check i have added another answeer!!

Hi Augustin,

you can use $authcontext.getUser().getName()=='user1'

and follow link to know about velocity variables.

Thanks a lot :)

appreciated if accept as an answer.

Thanks a lot :)

Hi Bharadwaj,

I want to display the field only to the members who is belong to 'jira-users' group .

I have tried this above refrence URL ,but it is not displaying field even the user belong to 'jira-users' group

In the above example i have used 'Jira-users' instaed of 'Jira-administrators'.

check my answer i have updated!!


i am not sure how to hide the custom field name in velocity file

i have another solution to hide a field to specific group/user with javascript, add the following script as webresource in a plugin

&lt;script type="text/javascript"&gt;  
jQuery(document).ready(	function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) {
function hideField(){
        var user=getCurrentUserName();		
		var statusText=$('#status-val').text();	
		if(isUserInGroup(user,'Developers') ){
			//to hide field
		}else  {

function getCurrentUserName()
var user;
        url: "/rest/gadget/1.0/currentUser",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            user = data.username;
     return user;
function getGroups(user)
var groups;
        url: "/rest/api/2/user?username="+user+"&amp;expand=groups",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            groups = data.groups.items;
     return groups;
function isUserInGroup(user, group){
    var groups = getGroups(user);
    for (i = 0; i &lt; groups.length; i++){
         if (groups[i].name == group){
              return true;
    return false;

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,660 views 18 21
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you