Hey guys,
I'm using JIRA Misc Workflow plugin to add a Groovy-based comment as a post function. Using Groovy I'd like to extract value from a custom field, which is a user picker.
What I've been trying so far was:
def user = issue.getCustomFieldValue('field_name').name;
Or
import com.atlassian.jira.component.ComponentAccessor; def customFieldManager = ComponentAccessor.getCustomFieldManager(); def user = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("field_name"))
I've tried to save the values in a String as well (instead of def).
Non of these actually work. Log shows:
[jmwe.plugins.functions.CommentIssueFunction] Error while executing SetFieldValueFunction: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getCustomFieldValue() is applicable for argument types: (java.lang.String) values: [field_name] Possible solutions: getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField), setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object)
Do you have any ideas what could work here?
Thanks
Community moderators have prevented the ability to post new answers.
There are two variables injected in the Groovy context:
So you can either use issue.get("customfield_12345") or your code but with issueObject instead.
Thansk David. Works like a charm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@David [Innovalog] Could you clarify this response? I am attempting, like Peter, to add the value of a User Picker custom field to a comment as a string. (One caveat: The goal is actually to @mention that user.) Thus far, I have been unable to get the value from this field to show up in a comment at all. I have confirmed that other custom fields (which are already stored as strings) are working correctly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To get the value of the custom field of type User Picker, you can use the following snippet: issue.get("myFieldName").getDisplayName()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, @David [Innovalog]! Getting closer! At this point, I am able to display the user's full name (i.e. Lana D Wright), but in order to @mention them, I need what I assume to be the database string: ~LWright
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe you need @Laurence Wright instead. You can try something like: "@" + issue.get("myFieldName").getName() + ""
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That did it! Thanks so much! In the end, my code looks like this: String approver = issue.get("customfield_xxxxx").getName(); String message = "Instructions for user."; String comment = "@" + approver + " " + message; comment;
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.