Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to reference a custom field value in a Script Runner, Post-Function, Script workflow function, Send an email based on the provided template if conditions are met

JoeR October 25, 2013

I'm having trouble understanding how to pull in a custom field within the Script Runner, Post-Function, Script workflow function, Send an email based on the provided template if conditions are met, EMAIL TEMPLATE section. Mouthful!

I've looked at the examples, none really talk about custom fields.
I can reference the Issue Key by using $issue.key, I can access the Summary using $issue.summary

The custom field name, for an example, would be "My Custom Field"
How do I reference it?
$issue.mycustomfield
or
$issue.mycustomfield.value
or
$issue.myCustomField
or $issue.myCustomField.value
Confused! Do I need to write a more elaborate script to get to custom field.

Can I use velocity

cfValues['My Custom Field']

or

cfValues['My Custom Field'].value

They didn't work.

I can do this in JETI using $!jetiFieldRenderer.renderCustomField($issue, 'customfield_11111')
not sure how to do this in script runner. I would use JETI, but I'm doing a condition test on a multiselect field and if true I send the email.

Here's the EMAIL TEMPLATE, short and sweet, how to reference a custom field?

Please review this issue:
<br>
Issue Key: $issue.key
<br>
Issue Summary: $issue.summary
<br>
Here's a link to the issue <a href='https://jira.mutualofomaha.com/jiraifs/browse/$issue.key'>$issue.key</a>
<br>
My Custom Field value is: ?????

The reason I want to send the value of the custom field is so the recipient doesn't have to
go into the issue to cut and paste the value, it will be sent to them in the email. A condition
test is causing me to not use JETI which is working well for some other emails I generate.
Thanks!

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
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.
October 25, 2013

Hi Joe - there is an example of this in the sample template provided in the docs: https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_send_a_custom_email

 

JoeR October 25, 2013

Jamie, that works amazingly well, first try! I was looking at the http://docs.codehaus.org/display/GROOVY/Groovy+Templates#GroovyTemplates-GStringTemplateEngine docs, should have looked at your docs at https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Sendacustomemail

Thanks for your excellent plug-ins and quick responses!

Lakshmi Kiran Ponnapalli December 10, 2013

Hi,

I have a problem in setting custom emails using this pluign. in To Address filedls how to use a custom field email to send address

i have used email teamplate as shown in the document but to address always hard coded in the document. where as my case i have to use a custom filed values in email.

i used following coding style in to address but its throwing errors.

1. <% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Question Answerer")).emailAddress %>

2. ${cfValues['Question Answerer'].emailAddress}

3 cfValues['Question Answerer'].emailAddress

could you please help me

Lakshmi Kiran Ponnapalli December 13, 2013

Hi,

Finally i found the solutions. we need to use customfield_xxxxx number in the To Fields values.

Thanks for your support.

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 12, 2014

Hi Whats the best way to put null check for this-

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

would this work -

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

Piyush_Annadate July 24, 2019

this works - <% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Severity")) %>

0 votes
Piyush_Annadate July 24, 2019

Use this - <% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Severity")) %>

0 votes
Lakshmi Kiran Ponnapalli December 10, 2013

Hi,

I have a problem in setting custom emails using this pluign. in To Address filedls how to use a custom field email to send address

i have used email teamplate as shown in the document but to address always hard coded in the document. where as my case i have to use a custom filed values in email.

i used following coding style in to address but its throwing errors.

1. <% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Question Answerer")).emailAddress %>

2. ${cfValues['Question Answerer'].emailAddress}

3 cfValues['Question Answerer'].emailAddress

could you please help me

TAGS
AUG Leaders

Atlassian Community Events