Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Add current user name to comment

Rodney Sawyer
Contributor
March 15, 2017

I am adding a post function to a workflow that just adds a pretty comment for an approval transition.   I can get the username into the comment, but I need the users full name.  

Here is my code:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category
 
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
commmgr = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class)
commmgr.create(issue, currentUser, "$currentUser Approved this ticket", true)
issue.store()

2 answers

1 accepted

5 votes
Answer accepted
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 16, 2017

You can use the code below to get the current user's full name:

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def fullName = currentUser.displayName
Rodney Sawyer
Contributor
March 16, 2017

Thanks Adam... exactly what I was looking for! 

0 votes
cptBarbosa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 15, 2017

Hi Rodney, I looked for some answers and found two links that may help you.

first

second

Hope they help you. smile

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25 europe, atlassian event, barcelona 2025, jira, confluence, atlassian intelligence, rovo, ai-powered collaboration, developer tools, agile teams, digital transformation, teamwork solutions, atlassian conference, product announcements

🌆 Team '25 Europe registration is now open!

Join the largest European gathering of the Atlassian Community and reimagine what’s possible when great teams and transformative technology come together. Plus, grab your Super Fan ticket now and save over €1,000 on your pass before prices rise on 3 June.

Register now
AUG Leaders

Atlassian Community Events