Need a way to clear "Epic Link"
Asked by Aisha M:

We have instances where, when a Story (which is linked to an Epic via the "Epic Link") is changed to an Epic, the "Epic Link" doesn't get removed. The other Epic continues to List this Issue (now AN Epic) under its "Issues in Epic" tab.

Is there any way to remove the Epic Link when a Story is changed to an Epic ?

We had a similar scenario with Parent link \& implemented the below fix given by Atlassian,

<https://confluence.atlassian.com/automationkb/automation-for-jira-how-to-clear-the-parent-link-field-when-an-issue-is-moved-to-a-new-type-1206795140.html>

But, when I try the same steps with Epic Link, it doesn't work.

Any help on this is much appreciated. Thank you !


Answers:
author: Antoine Berry
body: I have looked into Atlassian's workaround, but it is indeed not working on my instance for the Epic Link field. Instead, I did as follow with success :

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

Let me know how that goes for you.

comments: author: Aisha M
body: [@Antoine Berry](/t5/user/viewprofilepage/user-id/408560) For some reason, I still see the converted Epic (which used to be a story) showing up under the other Epic's "Issues in Epic" section

++**Here is how I tested**++

Created a Story . Then updated its "Epic link" with an Epic

Now converted this Story into an Epic.

But the original Epic still listing this converted Story under it


author: Antoine Berry
body: Can you check the Audit log of the automation rule ? You should see an error if the rule is correctly created and applied.

I tested exactly like you did and it worked fine.


author: Aisha M
body: Let me test the Automation set up in our UAT instead . . \*fingers crosses\*


author: Aisha M
body: The audit shows success. But, I still find the old parent of the Story listing the Story (now an Epic) under "issues in epic" . . Basically, there is Epic listing an Epic (which is supposed to be wrong when taking the hierarchy of issues)

I also noticed, when I again move the Epic (Feature) back to a Story, the old Feature link comes back . . Which might mean it din get cleared in the first place

I also came across this very old Bug -

<https://jira.atlassian.com/browse/JSWSERVER-12133>


author: Antoine Berry
body: If you check the audit log, can you confirm that the success message looks as follows, adn that the datetime matches with the moment you moved the story ?

![remove epic link automation log.png](https://community.atlassian.com/t5/image/serverpage/image-id/337275i900E53F3B3C96DA5/image-size/large?v=v2&px=999 "remove epic link automation log.png")


author: Aisha M
body: [@Antoine Berry](/t5/user/viewprofilepage/user-id/408560) Yes, this is how the audit log looks for me too.

For you, did the Epic which was linked to the Story previously still list the converted Epic under it ?

Could it be because, the Automation is processing to remove the Epic Link AFTER its changed to an Epic, but in reality an Epic issue type does not have a Feature Link ? Will it be possible to remove the field that happens :(


author: Antoine Berry
body: Yes, the automation rule is working correctly. See attachment history of the Epic, you can see that the story transformed to Epic is removed.![Epic child removed.png](https://community.atlassian.com/t5/image/serverpage/image-id/337281i720BF421EF8E3235/image-size/large?v=v2&px=999 "Epic child removed.png")

Are your Story and Epic created in the same project ? If so, please try to reindex the project, and, if not working, try a global reindex.

What do you mean "Feature link" ? What is your version of Jira ?


author: Aisha M
body: We use the name change of Feature instead of Epic. Its the same Epic link, (but for us its the 'Feature Link") . . Our version is 9.4.14 . . Oh, okay, let me try to re-index the Feature project.

Actually, our team projects do not contain the Epic issue type. So, using Bulk update moved the Story to a new project and updated its issue type. Could that be the problem ? This is making me crazy, coz its a pretty basic automation rule, yet its not working for me. . lol :D:D

Just one more thing, when you change the converted Epic back to a Story, does the Epic Link come back or it stays empty ?


author: Antoine Berry
body: I am on 9.12.10, so there could be a discrepancy here. But I just tried not only moving the issue to another issue type, but also to another project.

And \*boom\*, the problem persists. Even after project reindex, the epic link is still there, on the parent.

And the automation shows success.

I guess it is a good ol' ScriptRunner use case then ...


author: Aisha M
body: Lol , so it works if its within the same project !! I guess that Bug ( <https://jira.atlassian.com/browse/JSWSERVER-12133> ) is still valid, but surprised why its been ghosted . . The workaround is rathe troublesome.   

If using Scriptrunner Listener, you think it could be possible ?


author: Aisha M
body: I tried using a Listener but that did not work either. Let me know if you want to try the listener ;)


author: Aisha M
body: For some reason, the listener works if I the issue type change is from Epic to Story, but not when its from Story to Epic . . The Epic Link just cannot be removed no matter what ! ;(;(;(


author: Antoine Berry
body: Hello [@Aisha M](/t5/user/viewprofilepage/user-id/1191523) ,

I have played around with the listeners, but somehow it does not trigger on move event, which is strange since I actually "Move" (literally click on the move button).

In some cases, it triggers on the Updated event, Do you have a similar problem ?  
I need to check and find a workaround.


author: Aisha M
body: Same errors, kind of

I have kept "All issue event, issue updated \& issue moved" . . For me it works when the issue type is moved within the SAME project . . But not when it is moved between different projects (even though, the listener is enabled GLOBALLY)


author: Aisha M
body: [@Antoine Berry](/t5/user/viewprofilepage/user-id/408560) At this point I have tried every possible way, Automation, Automation with script, Script listener - remove links, remove based on Field ID \& Issue type ID . . Everything works if its between same project.

Do you know any way to have a JQL to filter Epics with an "Epic Link" , or maybe filter out the Epics what are linked to an Epic . . Maybe could explore the option of using Jobs


author: Antoine Berry
body: Hello [@Aisha M](/t5/user/viewprofilepage/user-id/1191523) ,

That is actually a lead, I cannot reproduce the problem anymore, does this query return any issue ?

```
"Epic Link" is not empty and type = Epic
```


author: Aisha M
body: Nope . . Doesn't return anything . . .

Unable to find a query to list the Epics linked to an Epic , maybe because the Epic isn't supposed to actually have the Epic Link


author: Antoine Berry
body: And do you still actually have an Epic with another Epic listed in "Issues in epic" on the issue itself ?


author: Aisha M
body: Yup, I have an Epic under an Epic (as part of testing) . . . I have been testing left right \& center, at this point dreaming about Epic Links :D


author: Antoine Berry
body: Can you try to run this script in Script Console after replacing the issue key with your Epic (which was previously a Story)

```
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

// the issue key of the issue that will be added to an epic
final String issueKey = "ABC-123"


// the name of the custom field to update (in our case is the Epic Link)
final String epicLinkFieldName = "Epic Link"

def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueByCurrentKey(issueKey)

def targetField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(epicLinkFieldName)

targetField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(targetField), null), new DefaultIssueChangeHolder())
```


author: Aisha M
body: This script runs but nothing happens . . No logs, nothing ..


author: Antoine Berry
body: That's really strange, this script should clear the value if it exists...

Have you tried doing a global reindex (no background) and see if there is any improvement ?


author: Aisha M
body: The same script works if its a STORY issue type . . But doesn't work if its an Epic  

Actually everything works ONLY if the issue type change is between same project


author: Antoine Berry
body: Hello [@Aisha M](/t5/user/viewprofilepage/user-id/1191523) ,

I think you should open a ticket at atlassian support. They will probably analyze your support zip and logs. This is what I do when I do when something similar happens on my instance.


author: Aisha M
body: [@Antoine Berry](/t5/user/viewprofilepage/user-id/408560) I have actually dropped it, because, nothing seems to work, and everything points to the Bug Atlassian has for the "Feature Link" . . the only work around available is to move the Feature back to story, remove the feature link and then convert it again . .


author: Aisha M
body: [@Antoine Berry](/t5/user/viewprofilepage/user-id/408560) Hellooooo ! Hope you are doing amazing :):) Can I please get your thoughts on this ? ;)

comments: author: Antoine Berry
body: Hello [@Aisha M](/t5/user/viewprofilepage/user-id/1191523) , glad to hear from you ! I am doing great, how a bout you ?

Do you want to achieve this for new issues only, or do you wish to clear your history ?

Could you please check the "Audit log" of the automation rule ?


author: ?ukasz Modzelewski _TTPSC_
body: If similar approach didn't work, it is possible that it is a bug, reach out to Atlassian support with this case

comments: author: Aisha M
body: [@?ukasz Modzelewski _TTPSC_](/t5/user/viewprofilepage/user-id/1144009) Thank you ! Just wondering why its not possible to clear a field when issue type is changed using Jira Automation


Tags: automation

data-center

epic-link

jira-data-center