How do I get the value of custom field in Send custom email post-function?

Szymon Trocha July 19, 2019

Hi,

I configured a "Send custom email" postfunction and it should use on of my custom fields (Text field type) to fill in the subject and body template. I looked at https://community.atlassian.com/t5/Marketplace-Apps-Integrations/How-to-add-a-text-custom-field-value-to-custom-email-script/qaq-p/456714 and https://scriptrunner.adaptavist.com/4.3.6/jira/builtin-scripts.html#_send_a_custom_email but none of this seems to work for me.

This is a subject template I use:

${issue.key} My subject: <% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("customField_name")) %> ${cfValues['customField_name'] ?: ""}

This is body template I use:

Custom field value: <% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("customField_name")) %>

${cfValues['customField_name'] ?: ""}

In an email I get:

Subject:

JSD-123 My subject: &lt;% out &lt;&lt; issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("customField_name")) %&gt;

Body:

For issue.getCustomFieldValue... I get Java error during Preview although this exactly follows the example in https://scriptrunner.adaptavist.com/4.3.6/jira/builtin-scripts.html#_send_a_custom_email :-(

Using ${cfValues['customField_name'] ?: ""} returns nothing similarly to subject

Any ideas? Documentation seems not to be helpful here or I'm missing something.

regards,

Szymon

1 answer

0 votes
Andrew
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.
July 19, 2019

Hi @Szymon Trocha 

I have checked on my instance, work well.

${getWorkflowButtons.call()}
test
Custom field value: <% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("ios dev")) %>

Could You please check name of the custom field?

A.PNG

B.R.

Szymon Trocha July 22, 2019

Hi Andriej,

Thank you for help. It works now when I used:

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

Do you maybe know and can explain why I needed to use ComponentAccessor instead of componentManager and the the full path "com.atlassian.jira.component.ComponentAccessor" ?

Regards,

Szymon

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events