How to use a custom user picker field in 'To issue fields' when sending a custom mail with Script Runner

Thomas Heidenreich
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.
April 2, 2012

Using ${cfValues['myCustomFieldName'].email} in the template works fine, but neither of these work as 'To issue fields' to determine the mail recipient:

cfValues['myCustomFieldName'].email

cfValues['myCustomFieldName']

${cfValues['myCustomFieldName'].email}

${cfValues['myCustomFieldName']}

So, what am I doing wrong? Or do I have to copy the mailadress to a scripted field an read it from there (if so, how do I do that)?

Thanks for any help

Thomas

edit:

Using ${cfValues['myCustomFieldName'].email} in the template works fine!

3 answers

1 accepted

1 vote
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.
April 6, 2012

In the to section, you should just enter the ID of the custom field, eg customfield_9999. If it's the right type, for instance a User custom field, then it will be handled.

Your code is correct for the template, but that's processed different. The to list is just a list of fields, rather than a groovy program that is processed.

Thomas Heidenreich
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.
April 9, 2012

Thanks,

that works for the usual user picker fields - sadly it does not work for the 'Last Resolution User' from the Jira Enhancer plugin. Any idea how to get that working?

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.
April 9, 2012

It would need to extend UserCFType, or I'd need to cater for it specifically.

francis
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
August 20, 2013

Hi Jamie,

How would you specify a 'scripted field' (of type string) in the 'to issue field'
It currently returns

2013-08-20 21:53:48,062 http-8080-6 WARN admin 1313x477x1 1inm9te 127.0.0.1 /secure/CommentAssignIssue.jspa [canned.workflow.postfunctions.SendCustomEmail] Unhandled custom field type customfield_11901

If this is not supported, would there be a workaround ?

Francis

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.
August 20, 2013

Hi Francis,

The version released about 10 minutes ago (2.1.11) is less fussy about the field types. So long as .toString() on the field value looks like an email address, or a comma-delimited list of email addresses, it should work.

francis
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
August 20, 2013

What a great amazing unexpected turnaround


My only problem is that this instance is JIRA 5.0.7. :-/
Can I backport your change to groovyrunner 2.0.7 ?

francis
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
August 20, 2013

And the answer is yes.

Just follow the 'Built-In Scripts Hacking Notes'
https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Built-InScriptsHackingNotes

(copy the sendCustomEmail.groovy out of groovyrunner-2.1.11.jar)

Thanks J, much obliged.

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.
August 20, 2013

;-) no problem. That particular thing of sending mail to a recip provided by a scripted field has not been tested that much, LMK if you have any problems.

francis
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
August 20, 2013

It works perfect on scriptrunner 2.0.7 and JIRA 5.0.7
We have now a scripted field which retrieves the email address of the contact person out of the CRM, and a script listener sending email when an issue is resolved or requires feedback. It took about a couple of hours to get it up and running (and tested)

Arianna Fabbri November 26, 2015

Hi @Jamie Echlin [Adaptavist], in To field is possible to use a Scripted field with template user picker? I've tried but it seems that this is not working. Thank you in advance

0 votes
Brent Webster
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.
April 25, 2012

I have a custom field: "Account Name" defined as a select list. It's be data filled with 20 or so name of various companies. I'm using the bulidin script to send a custom email and in the template I specified

Account Name: $cfValues['Account Name']

But the email contains:

Account Name: [Account Name:AT&T Wireless Group, Contact Name:Bob Smith, Customer:null, Customer Severity:P1 - Network is down and business is impacted, Fixed in Revision:null, Found in Revision:null, Gating:null, MKSid:null, MKSid_URL:null, Modifications:null, PV Prime:null, Planned For:null, Platform:[ALL], Ref #:null, Reviewer:null, Testcases:null, Verified in Load:null]['Account Name']

I want it to say

Account Name: AT&T Wireless Group


So what am I missing?

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.
April 25, 2012

Brent, this should be a new question. Select lists have Option values, to get the string value you want:

Account Name: $cfValues['Account Name']?.value

0 votes
Dieter
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.
April 3, 2012
cfValues['myCustomField'].emailAddress if myCustomField looks like customfield_xxxxxx, where x is the id of your custom field

Suggest an answer

Log in or Sign up to answer