Getting value of a custom field into custom email template

Arpan Mehetre January 25, 2017

I have created a Post Function which sends a custom email on transition of a workflow state. The email format is of type HTML and hence am sending the details using HTML tags.

If I want to include the system fields I use - <td>${issue.priority.name}</td> and the value of Priority fields gets fetched and displayed into my email template. But when I use the same(for eg., <td>${issue.priority.tool}</td> as tool is a custom field) to get the value of a custom field it doesn't work.

I referred - https://answers.atlassian.com/questions/12161743 and tried - <td>${issue.getCustomFieldValue("customfield_10401")}</td> I get the following error -

ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: TEST-117, 
actionId: 11, file: null
groovy.lang.MissingMethodException: 
No signature of method: com.atlassian.jira.issue.IssueImpl.getCustomFieldValue() 
is applicable for argument types: (java.lang.String) values: [customfield_10401]
Possible solutions: getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField), 
setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object)

 

Please help. Thanks.

 

1 answer

1 accepted

1 vote
Answer accepted
Thanos Batagiannis _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.
January 25, 2017

Hi Arpan,

try in the email body

&lt;%
def cf = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("TextFieldA")
def cfValue = issue.getCustomFieldValue(cf)
%&gt;
&lt;td&gt;$cfValue&lt;/td&gt;

Also which version of ScriptRunner you use ?

regards, Thanos

Arpan Mehetre January 26, 2017

Wonderful. This works. I am really not sure which version I am using. I am new to this. I am just using web based editor to edit the email templates using HTML format. Also, can you help in - how I can find previous workflow state and provide it into an email template? I just want to tell user that the workflow state has been changed from-to.

Thanks

JamieA
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.
February 3, 2017

transientVars is available to you, so you can get that information using https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/get-workflow-vars.html

Rather than writing in the template you can inject in some extra variables: https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_additional_configuration_in_emails

 

Manoj September 21, 2022

I am getting the custom field values is null in the email template which is triggered from workflow post function however in preview it shows the values appearing, any suggestion?

Suggest an answer

Log in or Sign up to answer