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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published Monday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

476 views 7 8
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