Sending an Automated Email when a Link is Added or Removed from an Issue
Asked by Doug Slay:

I have established a Change Management project where we create Change records to track what we are intending to deploy. As part of each of these CM issues, we link tickets from our development project using the link type of "is action item for".

I would like to send an email to a set of individuals when a new linked item as been added to the CM ticket, but only if the CM ticket is in one of a specific set of statuses (Authorize, Awaiting Implementation, Implementing).

I would also like to send an email when one of these linked items is removed from one of the CM tickets, if the CM ticket is in one of a specific set of statuses (Authorize, Awaiting Implementation, Implementing).

One development ticket could appear in more than one CM ticket.

Currently, I can get the "Add" use case to work as long as the development ticket is not associated to any other CM ticket.

The "remove" use case is not working in most cases at the moment.

If I remove the CM ticket in a specific status condition all emails are generated, but this spams my users during our planning process.

Any help would be greatly appreciated.

![Remove_Use_Case.png](https://community.atlassian.com/t5/image/serverpage/image-id/237266iD775AECE20094DC3/image-size/large?v=v2&px=999 "Remove_Use_Case.png")![Add_Use_Case.png](https://community.atlassian.com/t5/image/serverpage/image-id/237267i9BD1FCB255C16F6D/image-size/large?v=v2&px=999 "Add_Use_Case.png")


Answers:
author: Darryl Lee
body: Ok, links always are tricky.

So let's see if I've got this right:

For example: CM-104 is the Change Management issue. And you are ADDING or REMOVING links to SLAYCRM (is that the Development Project)?

Question: "Is an action item for" similar to "Blocks"?

I mean to say: you expect all SLAYCRM tickets to be completed before CM-104 can move forward in its workflow?

In my testing, in the scenario above, the trigger "When: Issue Linked" actually considers SLAYCRM to be the "triggering" issue.

So I think this means that first off you should probably use an "Issue fields condition" to see if the Project is SLAYCRM. But you're wanting to send an email about CM-104. Something like:  

"For issue CM-104, this new issue, SLAYCRM=123 was added as an action item."

ANYWAYS though, I did a bit of testing, and this bit of informational text is very useful:

![Screen Shot 2023-01-31 at 10.52.59 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/237469i6BB2C8E682446362/image-size/large?v=v2&px=999 "Screen Shot 2023-01-31 at 10.52.59 AM.png")

So I believe in your scenario "Dev" is the source issue, and the "Change Management" is the destination, and you can use that **{{destinationIssue}}** smart value to check that something is being linked to a CM issue.

Anyways, I did this test: my "Change Management" project is BT. And my "Development" project is SIM. You can add as many conditions about that linked issue as you want.

![Screen Shot 2023-01-31 at 10.56.05 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/237470i4A67DAEA521AF97A/image-size/large?v=v2&px=999 "Screen Shot 2023-01-31 at 10.56.05 AM.png")

From my BT issue, I would add a link to SIM that was "In Progress".

This rule picks up on the new link that was added, checks that it's SIM, and THEN checks that the project it linked to was BT, and if so, sends the email.

I realize this is confusing. :-}

You need to **play with it**, and I HEARTILY RECOMMEND 1) setting up a Sandbox/free instance/test projects to try this in, 2) adding a ton of Audit Log messages and write out things like TRIGGER: {{issue.key}} and LINKED ISSUE: {{destinationIssue.key}}, and then 3) test test test.

There is excellent instructions here: [Debug an automation rule](https://support.atlassian.com/cloud-automation/docs/debug-an-automation-rule/)

comments: author: Doug Slay
body: Thanks Darryl. The Change Management ticket CM-104 includes links to the development project (SLAYCRM). Those links are established as "Is action item for". A development ticket will be associated to 2 CM tickets (one for UAT and one for PRD).

The intent is that I send an email to our stakeholders if we add a new link (SLAYCRM) or remove an existing link (SLAYCRM) from the Change Management ticket (CM-104), but only if the CM ticket is in a specific status. That condition is what is causing this to fail. If I remove the condition, I get the email send anytime I add or remove; however, this will spam the stakeholders as we add the associated tickets during our planning phase.


author: Darryl Lee
body: Ok got it.

So as I mentioned, the best thing to do is create a test instance or project, and try this there. Ideally you would add Audit log messages to check the values like:  

LinkType: {{linkType}} \| Status: {{issue.status}} \| Mercury Env: {{Mercury Environment(s)}} etc.

Then you can sure that any conditions you are checking are applied to SLAYCRM rather than the CM tickets. Otherwise you might need to adjust your trigger to the corresponding link type to "Is action item for". (Like maybe it's "Is blocked by this action item?")

ALSO I would recommend that you try using the Field Comparisons rather than JQL. You can more easily test exactly where something might be going wrong.


author: Darryl Lee
body: Hi [@Doug Slay](/t5/user/viewprofilepage/user-id/3130199) --

I wonder if part of the problem with too many emails is because you aren't checking to see if the linked or unlinked issue is part of the dev project?  

Could you try adding:

```
AND Project=ME
```

to your JQL condition check?

comments: author: Doug Slay
body: The status condition is based on the Change Management project (CM) and not the development project (ME). Should I add that project to the query?


author: Doug Slay
body: [@Daryl Lee](/t5/user/viewprofilepage/user-id/4448319) , I updated the JQL to include the project reference and still no luck.

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

This SLAYCRM-217 is associated to CM-104 which is in the correct status.