How to create a mailto: Link in a ScriptRunner Web Item

I have a Custom web item and it must open the user's mail client using the mailto: link. I am able to pass many of the values in the link, but the one that is eluding me is the value in the custom field called "E-Mail".

 

I know ${issue.get('E-mail')} will not work in SR - it is a desperate attempt at using JMWE notation after everything else has failed.

 

How do I get the value of the 'E-mail' field?

 

image2017-1-18 18:36:32.png

2 answers

1 accepted

1 vote

Velocity is just not flexible enough to handle that syntax.

You can do it by using a ContextProvider to make a variable called $email available in the velocity context.

You can see how to do that in this example: https://answers.atlassian.com/questions/43888344

issue.getCustomFieldValue is the method you're after. Using it in the link there is likely to be a bit unwieldy, but it should be possible inside of closure braces.

issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find{it.name == "My Custom Field"})

Full disclosure: I've not tested that, nor am I 100% certain that it's necessary to fully qualify the ComponentAccessor class package.

Hi Jonny, I had tried this before, but it does not work.

Using the following as a link works perfectly, (but obviousy there is no email address):

mailto:?subject=[JIRA] (${issue.getKey()}) ${issue.summary}&bcc=${issue.projectObject.email}

 

Using the following:

mailto:${issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find{it.name == "E-mail"})}?subject=[JIRA] (${issue.getKey()}) ${issue.summary}&bcc=${issue.projectObject.email}

 

causes an error. Log file entries for the error start with:

2017-01-18 23:25:01,499 http-nio-127.0.0.1-8080-exec-19 uri:/secure/AjaxIssueAction!default.jspa username:cnielsen ERROR cnielsen 1405x55561x1 146b1tl 172.16.0.1,127.0.0.1 /secure/AjaxIssueAction!default.jspa [velocity] Parser Exception: getEncodedBodyFromContent
2017-01-18 23:25:01,501 http-nio-127.0.0.1-8080-exec-19 uri:/secure/AjaxIssueAction!default.jspa username:cnielsen ERROR cnielsen 1405x55561x1 146b1tl 172.16.0.1,127.0.0.1 /secure/AjaxIssueAction!default.jspa [velocity] org.apache.velocity.runtime.parser.ParseException: Encountered "{" at line 1, column 135.




Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 2 hours ago in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

13 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you