Help programming an auto-comment for when a comment is added to a closed issue
Asked by Mike Thomas:

When an issue has been resolved/canceled and someone happens to add a comment to it, the assignee is not notified due to it being closed. I wanted to create an automation to generate a comment which would then send an email in the even someone happens to add a comment on a closed/cancelled issue.

When creating this automation, it was working but what we learned was happening is when someone went to resolve a case, this new automation would kick in right away and leave the new comment because the timing/order of the case being closed, it triggered it instantly. I then figured we could establish a 1-2 minute delay, which is where I'm getting stuck.

On the attached screenshot, if I change the **Second Value** to "-2", the automation works, however we are getting the same results as before (everything happening all at once). However, when I remove the negative sign, the automation simply isn't working.

I've removed the negative sign and went in and added a comment to my test closed case, but i'm getting no results from this automation. My hope here is by removing the negative sign and once i place a comment on a closed case, in 2 minutes the automation would kick in and add the comment. Note; If I add back in the negative sign (-2), it works but for any open cases that get closed, we are back to square one where this automation kicks in and adds the comment when someone resolves the case.![jira_comment1.JPG](/t5/image/serverpage/image-id/322189i9C5EDC9304C64247/image-size/large?v=v2&px=999 "jira_comment1.JPG")![jira_comment2.JPG](/t5/image/serverpage/image-id/322190iC9870AD59AD1BD03/image-size/large?v=v2&px=999 "jira_comment2.JPG")


Answers:
author: Kalyan Sattaluri
body: Hello [@Mike Thomas](/t5/user/viewprofilepage/user-id/5479407)

To clarify, when you mean notify the assignee, you mean, you will add a new comment to the issue and assignee will be notified? why not just send an email to assignee directly?

Either way, I am not understanding the problem statement, especially this statement:

"when someone went to resolve a case, this new automation would kick in right away and leave the new comment"

Does resolving issues also add a comment as well in your workflow?

If so, You could check if person who is commenting ( {{comment.author}} ) is also the person {{issue.assignee}}, if they are not equal, only then comment.

Finally, your current logic/check is not correct. Your rule fires immediately when a comment is put in, so your "diff" statement in screenshot will always fail. So thats not a right condition to check. You can compare commenter vs assignee before commenting /acting further OR, you need to find the right field which captures when its resolved and use that in your check.. some thing like, {{issue.comments.last.created.diff(resolved).minutes}} for example. I am just giving example.. you need to know which field holds when it was last resolved so you an use it..

Please try above options and let me know... also, If I am completly missing the point, do also let me know so I can also suggest better.. lol

comments: author: Mike Thomas
body: I tried playing around with the smart values a few different ways, and the one you mentioned but still no luck. My test case is canceled (see screenshot), however most of our issues would show Resolved. The way our workflow is, once an issue gets resolved, regardless if it's resolved/canceled, it auto-comments showing case resolved and the only time i was able to get this automation to work is when i mentioned adding a negative sign to the second value. Trying to get this automation to kick in 1-2 minutes after the last comment left just isn't working, and i know it has to be in the smart value.

I just tested again and clicked on Audit, and it shows me "No actions performed" due to the "Advanced compare condition" did not match the condition. This is all new to me so I'm learning, my apologies if my original post may have sounded confusing, I do feel i'm very close here.

Thx so much

![jira_comment3.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/322406iFD47A69AEC833711/image-size/large?v=v2&px=999 "jira_comment3.JPG")![jira_comment4.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/322407iEB5F2F24FFCFAAC1/image-size/large?v=v2&px=999 "jira_comment4.JPG")


author: Kalyan Sattaluri
body: Hello, quick check, your syntax is off. You are missing the "diff" keyword.

Can you please change the First value in your advanced compare to below and retrigger the rule by commenting on ticket which is Canceled...

{{issue.comments.last.created.diff(resolved).minutes}}

Also, before your If conditions, right after trigger, add a log statement and log the same value so we know whats getting captured, like I have in my screenshot below.

To add log statement, Do add component -\> new action -\> search for "log action" and in the selection put above smart value.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/322425iC344E4BF6135E3AB/image-size/large?v=v2&px=999 "image.png")


author: Kalyan Sattaluri
body: and run the rule and share audit log please so we can see whats getting logged,


author: Mike Thomas
body: Thank you. I added the "diff" back and have added a log statement as suggested. I went in and added another test comment to my canceled case, however, the automation is still not working. Attached are the audit results.

Ideally what should have happened is 1 minute after my comment was added, the automation should've left an auto-comment to the issue with the message listed in my "Then" rule. Any additional assistance here would be greatly appreciated.

Thx,

MT

![Jira_comment5.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/322442i8329A71EA5079C47/image-size/large?v=v2&px=999 "Jira_comment5.jpg")


author: Kalyan Sattaluri
body: Hello [@Mike Thomas](/t5/user/viewprofilepage/user-id/5479407)

Your diff is giving negative number so we are skipping the if condition. We need to switch the fields..

So, Change the syntax to below:

{{resolved.diff(issue.comments.last.created).minutes}}

In fact, you dont even need the comment created time stamp cause its it should be now.. so you can also use below syntax:

{{resolved.diff(now).minutes}}

and retrigger the rule.


author: Mike Thomas
body: Updated and added another test comment. It's working, although I'm now running into the same issue I ran into previously when I was able to make it work. If you see on the second screenshot, the timestamp is the same which is not good. I need this automated comment to hit shortly after the comment was added. In this case I added a "2" in the Second value and a condition of "greater than". My hope is that this rule would trigger 2 minutes after the last comment was made. My ultimate goal here is for any case/issue that has already been resolved/canceled, IF someone adds a comment to it once in that status then my rule would kick in and add my auto-comment 2 minutes after they left their comment.

Many thx for any more assistance with this,

MT

![Jira_comment7.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/322451i6447847AD0E0B70E/image-size/large?v=v2&px=999 "Jira_comment7.JPG")

![Jira_comment6.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/322452iC05BAD83141974A7/image-size/large?v=v2&px=999 "Jira_comment6.jpg")


author: Kalyan Sattaluri
body: Hello [@Mike Thomas](/t5/user/viewprofilepage/user-id/5479407)

Deep apologies. Maybe I misunderstood the ask from the beginning.

so to clarify, we cannot make the rule "wait" any time. There is no such option.

I thought what you wanted to do was to differentiate between comment put in "as part of issue getting resolved" vs "some user commenting on a closed issue".

That way you can decide if you want to respond to the user's comment or not.

so I guess we need to go back to driving board and rethink the requirement.

But at a big picture, we cannot set up the rule where it "waits" or does something at a specific time of the day unfortunately. Sorry for leading you to wrong path.


author: Mike Thomas
body: No worries, thanks for the help. With our current workflow, anytime a comment is added, the reporter/assignee/additional assignees are notified via email. Once that case is resolved or canceled, if anyone (doesn't matter who) adds a comment to it, nobody is notified for some reason. I looked into seeing if we could disable the option to add a comment once a case has been resolved, however an admin advised me of the following;

"*It cannot be done* . A*s a template projects your workflows are shared with numerous project, any change you would want would impact all other projects that may not want the same thing you do.*

Since we are unable to use the "greater than 1 minute" rule, and since we cannot disable comments from being added on resolved cases, do you know if there's a way we can trigger an email to the reporter and assignees in the event a comment was added to a resolved case?

Ty in advance,

MT

![jira_comment8.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/322503i708A3E2080548D4D/image-size/large?v=v2&px=999 "jira_comment8.JPG")


author: Kalyan Sattaluri
body: Hello Mike,

Yes. In the last rule you have written and shared the screenshot, after all the If conditions, instead of you putting a comment in the issue, you can just send an email to the assignee and reporter that a new comment was added. And you can put in the details for them to review.

To do this, you go to Add Component -\> new action -\> send email and then you can use {{assignee}} and {{reporter}} smart values in the To / CC section. You can also use your email for test purposes, such as Mike.T@example.com in the To to check the email formatting.


author: Mike Thomas
body: Thank you and this would be ideal, but if you notice in my last screenshot the trigger took place the moment someone resolved a case. I just removed the comment option and added an email only option. In testing this morning, while the emails go out no issue, its sending them out on the same timestamp when a case moves from open to resolved (*see screenshot*)

Thx for any additional feedback based on this.

-MT

![jira_comment9.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/322684i305D6DB62108C99D/image-size/large?v=v2&px=999 "jira_comment9.jpg")


Tags: automation

jira-service-management

unknown-hosting-type