Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Does anyone have a code snippet to display a group name in a jira email notification

Maria DePasquale
Contributor
October 16, 2020

I have a Post Transition Script to send an email.  I can't figure out how to display the name of a Group Field selected on a ticket.  

I was trying to use this:

Testing Group : <% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Testing Group")) %> \n

The group name is not rendered.  I get this instead:

Testing Group : [com.atlassian.crowd.embedded.impl.ImmutableGroup@c2848020] 

The above code does work for displaying a user name in a user field however.

I also tried this:

def groupManager = ComponentAccessor.groupManager
def customFieldManager = ComponentAccessor.customFieldManager
def groupNameField = customFieldManager.getCustomFieldObjectByName("Testing Group")
def groupNameSelected = issue.getCustomFieldValue(groupNameField) as List
def gn = groupNameSelected[0].toString()
def group = groupManager.getGroup(gn.getName())

... but to no avail.  I'm guessing this is easy for an experience groovy programmer... thoughts?

 

 

 

 

 

 

2 answers

0 votes
Boris Berenberg - Atlas Authority
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.
October 17, 2020

If you don't want to write scripts to include fields in custom notifications, take a look at an app that allows you to pick fields in an easy email template configuration UI like Notification Assistant for Jira (we make this)

Maria DePasquale
Contributor
October 19, 2020

Thanks but a purchased solution is not possible.

0 votes
Nic Brough -Adaptavist-
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.
October 17, 2020

You're pretty close, just one more thing to add to your code.

The line

issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Testing Group"))

is getting a list of groups selected in the field, and the items on the list are group objects, not strings.  You're getting the [com...] because that's what Java does when you try to print an object out as a string.

Your second block of code is also going in the right direction, but the line starting "def gn = " is going to do much the same - it's converting a group object to a string. 

I think you can replace the "toString()" in that line with "getName()"

Maria DePasquale
Contributor
October 19, 2020

I tried your suggestion on the second code snippet... this code 

def groupManager = ComponentAccessor.groupManager
def customFieldManager = ComponentAccessor.customFieldManager
def groupNameField = customFieldManager.getCustomFieldObjectByName("Testing Group")
def groupNameSelected = issue.getCustomFieldValue(groupNameField) as List
def gn = groupNameSelected[0].getName()

yields this error:

he following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2020-10-19 10:06:37,700 ERROR Tab=postfunctions&workflowTransition=1&highlight=6
groovy.lang.MissingPropertyException: No such property: ComponentAccessor for class: Script7
 at Script7.run(Script7.groovy:14)

I believe this is the issue: def customFieldManager <-- deprecated but not sure how to replace


You didn't suggest which extra line I should add to the first code snippet. Since I tried about 50 different permutations of the first code snippet and searched the internet far and wide, I finally broke down to see if anyone had the code because I'm not an experience groovy tester.

My final workaround in the absence of code was to create a text field and use a Post Transition to copy the Group field entry to the text field and then simply display the text field in the email notification since I can get that to work in the script. I don't have unlimited time to get these issues resolved so I had to come up with something (albeit not very elegant).



def group = groupManager.getGroup(gn.getName())
 

Suggest an answer

Log in or Sign up to answer