Hi!
I am trying to add a automaticlly generated comment on an issue when it is transitioned. The comment should "tag/reference" a user that is stored in a single select user picker.
I almost got this working, but i am missing the last step.
My user is returned as a string and not an object. In the format "username(username)".
Is there a way to get the plain username?
And is it at all possible to add a comment that references a user? (Like adding a @username manually).
My post function script looks like this:
// Required Imports
import com.atlassian.jira.component.ComponentAccessor;
// Get a pointer to the current logged in user
def CurrentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
// Get the current Issue
def issue = issue;
// Get the Manager classes required
def commentManager = ComponentAccessor.getCommentManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
//Get the tester user from customfield
def customField = customFieldManager.getCustomFieldObjectByName("Reviewer"); //customfield_10304
if(customField) {
String user = issue.getCustomFieldValue(customField);
if(user) {
def CommentText = "Review requested @${user}";
commentManager.create(issue,CurrentUser,CommentText,true);
}
}
Thanks in advance!
Hi,
Custom field Reviewer has ApplicationUser type. But getCustomFieldValue method is general so it returns Object type. It's possible to cast returned value to ApplicationUser. And also mention user syntax is a bit different: [~${user.name}]. So the whole script could look like:
// Required Imports
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
// Get a pointer to the current logged in user
def CurrentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
// Get the current Issue
def issue = issue;
// Get the Manager classes required
def commentManager = ComponentAccessor.getCommentManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
//Get the tester user from customfield
def customField = customFieldManager.getCustomFieldObjectByName("Reviewer"); //customfield_10304
if(customField) {
def user = issue.getCustomFieldValue(customField) as ApplicationUser;
if(user) {
def CommentText = "Review requested [~${user.name}]";
commentManager.create(issue,CurrentUser,CommentText,true);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.