Using automation to send an email with the last 3 external comments
Asked by Robert _Bobby_ Mittendorf:

I've been looking for a way to build an automation that sends an email to request participants that contains the last 3 external comments. I was able to make a nicely formatted portion but it only seems to be able to run on ALL comments instead of external explicitly:

```
{{#issue.comments.getFromEnd(0)}}
Comment by {{author.displayName}} on {{created.format("MM/dd")}} at {{created.shortTime}}:

{{body}}
{{/}}
```

So now the closest I've seen for this would be to use advanced branching to loop through all comments and perform an action only when {{issue.comments.internal}} equals false. In a perfect world this could iteratively add to a "Send email" action step, but that doesn't appear to be possible. So the next logical step is to see if this can be used to iteratively create variables instead, something like {{externalcomment(\*)}} where (\*) is the iteration of said variable. Does anyone know if this (or something equivalent) is possible?


Answers:
author: Simmo
body: Hi [@Robert _Bobby_ Mittendorf](/t5/user/viewprofilepage/user-id/4430122),

I don't think that this is possible at the moment. The approach described by [@Mark Segall](/t5/user/viewprofilepage/user-id/4666637) isn't going to work as our branching happens async, so your main line can finish before the branches have and variables created on a branch are only scoped to that branch.

If it was just the last three comments it might be possible but without list filtering I can't think of a way to get the last three external comments.

comments: author: Robert _Bobby_ Mittendorf
body: Yeah I wasn't sure if that suggestion would work but I chalked it up to my explanation over anything else.

I DID figure out a way to do this though! I don't think it's a *good* solution, mind you, but it would work.

I would have an automation create a temporary issue, then use a For Each loop to conditionally add external comments to that issue. After that completes it would trigger another automation to extract the relevant comments (depending on order), put those in an email, and delete the dummy issue. I don't accept this as a viable solution because I would either have to create a large number of issues on this client's main project or set these automations to global to avoid messing with their increments.

This does make me think that an automation action that could do this without cluttering up metrics or increments would be very useful though.


author: Bill Sheboy
body: Hi [@Robert _Bobby_ Mittendorf](/t5/user/viewprofilepage/user-id/4430122)

Are you using Cloud or Data/Center version?

If you are using Cloud, I wonder if you could...

* using [smart value list filtering](https://community.atlassian.com/t5/Automation-articles/Filtering-smart-value-lists/ba-p/1827588), extract the external comments into a created variable
* split the created variable, and then grab only the last three (referencing with get(), adding conditional logic to handle when there are less then three comments.

I have not tried this exact scenario, so perhaps experiment with it.

Kind regards,  
Bill


author: Mark Segall
body: Hi [@Robert _Bobby_ Mittendorf](/t5/user/viewprofilepage/user-id/4430122)

I believe you're on to something with the variable approach. I can't find my example of this, but I'm pretty positive it worked... You'd basically set the equivalent of a declare where you give it some random value as a starter and then create the same variable inside the branch:

* Create Variable
  * varComment1
  * 0
* Create Variable
  * varComment2
  * 0
* BRANCH 1
  * Create Variable
    * varComment1
    * {{yourcomment}}
* BRANCH 2
  * Create Variable
    * varComment2
    * {{yourcomment}}
* Send Email
  * {{varComment1}}  
    {{varComment2}}


Tags: comment

email