Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Display last n comments

Vanessa Marie Delfin October 12, 2021

I am working on Automation to send the last n comments through email. For example, an issue contains 4 comments. Comments 1-4. I know that in order to get the latest comment I use {{issue.comments.last.body}}. Is it possible to show comments 2-4? 

1 answer

1 accepted

0 votes
Answer accepted
Bill Sheboy
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.
October 12, 2021

Hi @Vanessa Marie Delfin  -- Welcome to the Atlassian Community!

Have you tried this function: getFromEnd()

https://support.atlassian.com/jira-software-cloud/docs/smart-values-lists/#Smartvalueslists-list.getFromEnd-index-

You could first check if {{issue.comment.size}} is < 5 and then show the whole list, or use the function and count backwards for your values: 3, 2, 1, 0

Kind regards,
Bill

Vanessa Marie Delfin October 21, 2021

Hello @Bill Sheboy  Thank you for the welcome! 

I'm sorry I explained my situation wrong. If I have an issue that contains 10 comments and I want to print out the last 3 comments including the author's name

I thought about using the getFromEnd function like you suggested but it will not work in my situation since the index is static. For an issue with 10 comments, I will put 

getFromEnd(10)

getFromEnd(9)

getFromEnd(8)

but if the issue gets a new comment, now a total 11 comments, it will always get the comments 10 9 8.

I need something more dynamic and after looking at the link you gave me  it might not be possible. Would you happen to know of a different approach?

 

Bill Sheboy
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.
October 21, 2021

Hi @Vanessa Marie Delfin 

The index used in getFromEnd() is relative from the end of the list.  I just tried this again with my test rule, and when I use:

  • {{issue.comments.getFromEnd(2).body}}  -- I get the third from the end, no matter how many comments exist
  • {{issue.comments.getFromEnd(1).body}}  -- is second to last
  • {{issue.comments.getFromEnd(0).body}}  -- is the last one

 

Here is my test rule, which successfully wrote the correct comments to the audit log.

capture.png

Like # people like this
vincenzo.spatafora
Contributor
October 10, 2024

Hi @Bill Sheboy, happy to find you in here.

Would you know which is the syntax to get the second-last comment of a child issue?

I have tried the followings out but they haven't worked: 

{{issue.subtasks.comments.getFromEnd(1).body}}

{{issue.subtasks.comments getFromEnd(1).body}}

Thanks in advance,

Vincenzo.

Bill Sheboy
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.
October 14, 2024

Hi @vincenzo.spatafora 

My apologies for the delay in responding as I have been offline for a while.

 

Next thing, as this is an older thread, I recommend creating a new question, perhaps linking back to this one.  That will ensure the maximum number of people see it to offer suggestions.

When you create your new question, please include:

  1. what problem are you trying to solve; that is, "why do this"
  2. an image of your complete rule
  3. an image of the action / condition / branch where you are using that expression
  4. an image of the audit log details showing the rule execution

Those will provide context for the community to help.

 

From what I can see thus far in your rule syntax...

  • {{issue.subtasks}} is a list of issues;
  • for a specific issue, the comments smart value is also a list; and
  • thus when you use {{issue.subtasks.comments}} that accesses a list within a list, producing something like this, where the comment list for each issue becomes an array with square brackets (or empty brackets when there are no comments):
    • [ a comment 1, another comment], [], [more comments]

This results in getFromEnd() probably operating on the second-to-last subtask, and not comments.

Back up to point #1, what problem are you trying to solve, as that will indicate how to proceed?

 

Kind regards,
Bill

vincenzo.spatafora
Contributor
October 16, 2024

Thanks @Bill Sheboy

Sorry for the delay as well but I was off a couple of days.

In the meantime I have resolved it.

Thanks also for your suggestions.

Kind Regards, Vincenzo.  

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events