Add current user name to comment

Rodney Sawyer 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 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