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

Christian Nielsen January 18, 2017

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
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.
January 18, 2017

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

1 vote
Jonny Carter
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 18, 2017

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.

Christian Nielsen January 18, 2017

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
TAGS
AUG Leaders

Atlassian Community Events