How to retrieve multiuser field values in scriptrunner send custom email

Veda Bhat June 23, 2022

Hi All,

I am trying to send a custom email using "Scriptrunner send custom email" template where I am retrieving values of some issue fields. I am able to it successfully for summary, description etc but not able to understand how I can do it for multi user field "Implementer". The code that I used below extracts the Username(id) rather than the Full Display name. Rest of other fields are working as expected.

When I use .getDisplayName() method it errors out. Could you suggest a solution for it?

 

The following Change request has been approved (Issue $issue).

Summary:
$issue.summary

Description:
$issue.description

Approved Window Start:
<% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Approved Window Start")) %>

Approved Window End:
<% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Approved  Window End")) %>

Change Implementer:
<% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Implementer")).getDisplayName() %>

2 answers

1 accepted

0 votes
Answer accepted
Andrea Pannitti
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.
June 25, 2022

Hi @Veda Bhat,

I hope this solve your issue:

Change the last line as following:

<% out << ((issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Implementer")) as List<com.atlassian.jira.user.ApplicationUser>).collect { it.displayName }) %>

 

Veda Bhat June 25, 2022

This worked! Thank you so much!!

0 votes
Andrea Pannitti
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.
June 23, 2022

Hi @Veda Bhat,

you should change the last line as following:

<% out << (issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Implementer")) as com.atlassian.jira.user.ApplicationUser).getDisplayName() %>
Veda Bhat June 24, 2022

Thank you for you response! I tried modifying the last line as you mentioned above and got below error:

java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.mail.AbstractSendCustomEmail.constructMail(AbstractSendCustomEmail.groovy:240)
at java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.mail.AbstractSendCustomEmail.constructMail(AbstractSendCustomEmail.groovy:240)
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail.super$4$constructMail(SendCustomEmail.groovy)

Andrea Pannitti
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.
June 24, 2022

Hi @Veda Bhat,

your issue could be in the condition or in other sections of your ScriptRunner send custom mail. Please, could you report the configuration?

 

Veda Bhat June 24, 2022

Hi @Andrea Pannitti

I do not have anything specified under Condition and Configuration section of "Scriptrunner Send custom email". The reason is I have added this as a post function to a transition in a workflow. Whenever this transition happens it should send this email to a distro list .

All other fields are retrieving accurate values as you can see in result window below except this one multi user field called " Implementer" which retrieves user names as id instead of full name:

 

result.PNG

send custom email template.PNG

Andrea Pannitti
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.
June 24, 2022

Hi @Veda Bhat,

the problem was due to the fact that your custom field Implementer is a multi-user and not a single-user custom field. So, to solve the issue, look my last answer.

Suggest an answer

Log in or Sign up to answer