Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Comment issue post function based on Groovy

Peter Bengov
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.
December 8, 2014

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

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
David _old account_
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.
December 8, 2014

There are two variables injected in the Groovy context: 

  • issue: a wrapper that exposes only one method, get("<field_id")
  • issueObject: the JIRA Issue object

So you can either use issue.get("customfield_12345") or your code but with issueObject instead.

 

Peter Bengov
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.
December 9, 2014

Thansk David. Works like a charm

Lana Wright November 20, 2015

@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.

David _old account_
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.
November 20, 2015

To get the value of the custom field of type User Picker, you can use the following snippet: issue.get("myFieldName").getDisplayName()

Lana Wright November 20, 2015

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

David _old account_
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.
November 20, 2015

I believe you need @Laurence Wright instead. You can try something like: "@" + issue.get("myFieldName").getName() + ""

Lana Wright November 20, 2015

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;

TAGS
AUG Leaders

Atlassian Community Events