Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Mario June 15, 2020

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

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Ravi Sagar _Sparxsys_
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.
June 15, 2020

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

Mario June 15, 2020

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

Ravi Sagar _Sparxsys_
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.
June 16, 2020

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

Mario June 16, 2020

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

Ravi Sagar _Sparxsys_
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.
June 18, 2020

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

Mario June 19, 2020

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>

TAGS
AUG Leaders

Atlassian Community Events