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?
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)
Thanks but a purchased solution is not possible.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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())
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.