Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,317
Community Members
 
Community Events
168
Community Groups

Usage of "Send custom email" postfunction of scriptrunner in workflow

Hi there,

I'm quite new to Scriptrunner und just getting started. I want to use the "Send custom email" workflow postfunction of scriptrunner. Everything is almost fine but there remain two problems:

I'm using this body template:

<ul>
<li><b>Summary:</b> ${issue.summary} </li> <br>
<li><b>Issuekey:</b> ${issue.key}</li> <br>
<li><b>Priority:</b> ${issue.priority} </li> <br>
<li><b>Reporter:</b> ${issue.reporter} </li> <br>
<li><b>Created Date:</b> ${issue.created} </li> <br>
<li><b>Description:</b> ${issue.description} </li> <br>
<li><dl>
<dt><b>All Comments:</b></dt>
<br> XXX
</dl> </li> <br>
<li><b>Text123</b> <br> longer text sentence[...]
</li>
</ul>

1) The ouput of "priority" does not work. Neither in the preview nor in a real testmail. There always occurs:

Priority: IssueConstantImpl[[GenericEntity:Priority][sequence,4]statusColor,#EF612C[name,Very High][iconurl,/images/icons/priorities/major.svg][description,][id,10200]]

What am I doing wrong here? I just cannot figure out what is causing this?!

2) I need to include all comments of the issue (incl. a comment added during the transition of the triggering post function). Previously I've used the jmwe email issue postfunction, but it was limited as I need to change the real From-Sender-Address --> therefore I switched to the scriptrunner postfunction.

In the jmwe postfunction I used this code successfully (provided by the jmwe community leader) to catch all comments:

<%= issue.get("comment").collect{"<dd><li>"+it.bodyHtml+"</li></dd>"}.join('\n') %>

This does not work anymore in the template mentioned above.

How can I achieve in the scriptrunner postfunction to include all comments (at position XXX) of the affected issue in the template?

Thank you all very much for your help in advance.

Best regards
Mario

1 answer

1 accepted

1 vote
Answer accepted

Hi @Mario 

1. Try this for priority.

${issue.priority.name}

2. For last comment try this.

${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getLastComment(issue).body}

For  all comments try this.

${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).collect{it.body}.join('\n')}

I hope it helps.

Ravi

Hi @Ravi Sagar _Sparxsys_ 

thank you for the fast answer. 

1. is working as expected. ;-) 

2.

${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).collect{it.body}.join('\n')}

--> This does correctly provide all comments, but only as a single line:

13245 1324 blibla   1 bitte prüfen   alles ok done dfghjkl test test2 [^1234.txt] [^test.xlsx] test3 mit attachments test 4 + bes-support in to 123 first test scriptrunner built in mail custom

Do you see any chance how I can get all comments listed up one below each other? Best would be to have any kind of indicator when a comment ends and the next comment begins, e.g. that the comment has a "key point" indicator like "-" or s.th. similar?!

Thank you very much!

Best regards

Mario

Try with <br>. You can also enclose this with <li> to have them displayed as a list.

Hi @Ravi Sagar _Sparxsys_ 

thank you once again.

Sorry for the dumb question but where exactly within the code 

${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).collect{it.body}.join('\n')}

should I place "<br>" or "<li>[...]</li>?

No matter where I've tried it the preview always fails?!

Best regards

Mario

Hi @Mario 

Try this.

<ul>
${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).collect{ '<li>'+it.body+'</li>'}.join('<br>')}
</ul>

Make sure the email format is HTML.

I hope it helps.

Ravi

Works like a charm, thx a lot.

Here the complete code I'm using, if anybody needs it later on:

 

<% def commentManager = com.atlassian.jira.component.ComponentAccessor.getCommentManager() %>
<% def comments = commentManager.getComments(issue) %>

<ul>
<li><b>Summary:</b> ${issue.summary} </li> <br>
<li><b>Issuekey:</b> ${issue.key}</li> <br>
<li><b>Priority:</b> ${issue.priority.name}</li> <br>
<li><b>Reporter:</b> ${issue.reporter} </li> <br>
<li><b>Created Date:</b> ${issue.created} </li> <br>
<li><b>Description:</b> ${issue.description} </li> <br>
<li><b>All Comments:</b>
<ul>${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).collect{ '<li>'+it.body+'</li>'}.join('<br>')}
</ul>
</li> <br>
<li><b>Information:</b><br>Text[...]
</li>
</ul>

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

193 views 1 6
Read article

Atlassian Community Events