I'm new to Scriptrunner & groovy scripts, and I'd appreciate help & advice.
I have a Jira customfield of user-picker type, called "Process Manager", and I would like to add the "Process Manager" user as a user-mention in a issue comment triggered during a transition in workflow.
The results I keep getting is of string type (plain text) or null, unlike the assignee which is displayed as a user mention in the comment and thus getting notified by email.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.opensymphony.workflow.WorkflowContext
def customFieldManager = ComponentAccessor.getCustomFieldManager();
UserManager userManager = ComponentAccessor.getUserManager();
def processmgrCF = customFieldManager.getCustomFieldObjectByName('Process Manager');
def processmgr = issue.getCustomFieldValue(processmgrCF);
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
def fullText = "... by ${processmgr} and [~${issue.assignee?.key}]"
ComponentAccessor.getCommentManager().create(issue as Issue, userManager.getUserByName(currentUser), fullText as String, true);
How do I show the custom field as a user object type in a comment, like the assignee?
Hi Marianne,
A user-picker type custom field contains the same ApplicationUser type object as your Assignee field. With that in mind, you can mention a user in your custom field the very same way you do it with assignee. Something like this should do the trick:
def fullText = "... by [${processmgr?.key}] and [~${issue.assignee?.key}]"
Hi Ivan,
[${processmgr?.key}] didn't work for me, but following your suggestion and line of thought I modified it to [~${processmgr.name}] and that works.
def processmgrCF = customFieldManager.getCustomFieldObjectByName('Process Manager');
String processmgrName = issue.getCustomFieldValue(processmgrCF).name;
ApplicationUser processmgr = ComponentAccessor.getUserManager().getUserByName(processmgrName);
def fullText = "...by [~${processmgr.name}] og [~${issue.assignee?.key}]"
Thanks for your guidance!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.