It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Answer accepted

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
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

1,098 views 7 0
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you