Jira Automation: copy comments from trigger issue, is it possible?

Rosana Casilli
Contributor
May 9, 2022

Good afternoon all!

 

I have this question, an user is asking to create a rule to create a new issue based on data from trigger issue in a different project. 

The problem I have is that information that he needs includes comments. He wants to copy all comments (or internal notes only if it's possible) to this new issue in project AA

How can I copy the comments? maybe including a json? how should it be?

 

thanks in advance,

Ro

3 answers

1 accepted

2 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.
May 9, 2022

Hi @Rosana Casilli 

The issue comments are a list smart value, and so you could iterate over them to add to the new issue.  Please look here for information about the field: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/#--issue.comments--

Next, you asked about filtering to only copy the internal ones.  That can be done by using smart value, list filtering.  There is an example of filtering on internal comments in this article: https://community.atlassian.com/t5/Automation-articles/Filtering-smart-value-lists/ba-p/1827588

Kind regards,
Bill

Rosana Casilli
Contributor
May 9, 2022

Thanks @Bill Sheboy

 

I have another question (sorry! but never worked with comments on automation)

can I copy the comments from the original to the new issue? Because I have try to copy to a custom field, and worked but do not know  how to copy the original comments using smart values you suggested into the comment section in the new issue.

Is there any way? or should I use this custom field?

 

thanks in advance

Ro

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.
May 10, 2022

Hi, Ro!

Although you could use a custom field to store the copy, you could also add them as comments, either as one giant comment to the new issue or one-by-one (with an advanced branch).  If you take a look at those links I provided they show examples of how to iterate over the comments list for an issue.  For example:

{{#issue.comments}} 
Comment by: {{author.displayName}} at: {{created}}
{{body}}
{{/}}

 

Please note: if you copy them with an automation rule, there is currently no ability to sort a smart value list.  That means when you add the comments they will appear in a random order relative to the comments' date/time added.  If you want them in the order they were added, please investigate a marketplace addon, as @John Funk suggested.

Thanks,
Bill

Like # people like this
Rosana Casilli
Contributor
May 10, 2022

Still don't know where to put this and how.

I do not have "Comment" field available on "choose field to set". So, how can i associate:

{{#issue.comments}} 
Comment by: {{author.displayName}} at: {{created}}
{{body}}
{{/}}

to the comment field?

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.
May 10, 2022

After the issue is created, you may branch to it and then use the Comment Issue action.  For example:

  • trigger: whatever you are using
  • action: create issue
  • branch: on most recently created issue
    • action: comment on issue... adding information from the trigger issue to the new one
{{#triggerIssue.comments}} 
Comment by: {{author.displayName}} at: {{created}}
{{body}}
{{/}}
Like # people like this
Rosana Casilli
Contributor
May 10, 2022

Thanks Bill, but this won't work for my scenario.

My scenario is:

I have an issue in project A and want to copy or clone to Project B, and all comments from issue in  project A should be copy to the new issue in project B. 

 So when the Branch section is executed, it is looking for most recently created in the current project A (In the rule restricted to projects cannot be edited) 

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.
May 11, 2022

If this rule is running as a global/multi-project scope, I believe that would still work. 

If the most-recently-created branch does not work, a global/multi-project rule could still use JQL for your created issue key for the branch.

Please note, that there are execution limits per month for global/multi-project rules, so check with your site admin to confirm your limits before trying a global rule.

A more elaborate work-around which does not require a global/multi-project rule is to call the REST API from a web request in the rule to add the comments.

Mane Zakaryan
Contributor
October 19, 2023

Hello @Bill Sheboy 

In this context, can you please help me to understand why the system doesn't take my comment as needed.

In my automation rule, everything work well.

I have one Story automatically created with its sub tasks.

For this story I need to copy the last comment of my trigger issue.

So in the story I use the action ADD COMMENT and in the comment field I use the smart value {{issue.comments.last.body}}

 

But it doesn't return me my last comment in the trigger issue.

 

Is there an obvious mistake that I am making ?

 

 

 

Screenshot_10.png

 

 

 

I also tried other smart values like {{triggerIssue.get(0).comments.last.body}} or {{triggerIssue.comments.last.body}} but I have nothing.

It doesn't understand the issue that I want in fact. I will make also the start of my rule so you can see when it starts. After my JQL states and transitions are done my automation starts.

 

Screenshot_11.png

Mane Zakaryan
Contributor
October 19, 2023

In fact it can be done, if at the beginning of our rule we can clone the trigger issue, so after we can track it. But in cloning the problem is, that by default it will not clone the comment.

Mane Zakaryan
Contributor
October 19, 2023

This smart value worked. Try this one @Rosana Casilli 


{{triggerIssue.key}}:
{{triggerIssue.comment.last.body}}

 

But make sure that it is a trigger issue.

Screenshot_12.png

 

@Bill Sheboy  thank you and sorry to disturb you. I could find the solution.

Like Bill Sheboy likes this
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 19, 2023

Hi @Mane Zakaryan 

No worries, and I am glad to learn you figured it out!

And as an FYI...as this is an older post, it can help to create a new question and link back to the older ones for context.  Otherwise only the people mentioned or following the older threads will see it, limiting the suggestions you may receive. 

Kind regards,
Bill

Like Mane Zakaryan likes this
Andrea Rose November 8, 2023

I also use this for copying comments from the trigger issues. But if the trigger issue has no comments this causes an error. Do you have an idea how to add a condition to avoid this?

{{#triggerIssue.comments}} 
Comment by: {{author.displayName}} at: {{created}}
{{body}}
{{/}}
Like Bentley_ Andrea likes this
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.
November 8, 2023

Hi @Andrea Rose 

There are at least two ways to do this check:

{{#if(triggerIssue.comments.size.gt(0))}}
{{#triggerIssue.comments}}
Comment by: {{author.displayName}} at: {{created}}
{{body}}
{{/}}
{{/}}

 

Without seeing your complete rule, it is unclear the better way to use.

Kind regards,
Bill

Like Bentley_ Andrea likes this
Andrea Rose November 13, 2023

I've added this condition. Now it works as expected. Many thanks for your support, @Bill Sheboy

2023-11-13 15_41_11-Window.png

Like # people like this
Bentley_ Andrea June 12, 2024

Thank you! This is exactly what I was looking for, too!

3 votes
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 9, 2022

Hi Rosana,

We actually use the add-on called Deep Clone to do this. 

Rosana Casilli
Contributor
May 9, 2022

Thank you john! but there is no budget for add-on right now.. :(

Like John Funk likes this
0 votes
Pankaj
Contributor
April 6, 2024

Got it!.

Suggest an answer

Log in or Sign up to answer