Add cloned issue as Epic Link on transition

Ovidiu Vasilescu August 8, 2016

Heya,

 

I'm trying to do a nifty Epic Workflow which creates some tasks / stories on certain transitions. I want these Tasks to have Epic link the original issue they were cloned from. Note that they are cloned from the Epic itself, so they can't inherit the Epic Link of the issue they were cloned from since Epics don't have Epic Link.

I've tried a few things so far and this one I was expecting to work, any ideas why it isn't?

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}
issue.setCustomFieldValue(cf, sourceIssue.key)

 

Cheers,

Ovidiu.

2 answers

1 accepted

0 votes
Answer accepted
Ovidiu Vasilescu August 8, 2016

I tried a very dirty & basic workaround which solved a problem for me in the past:

  1. Create "Dummy" field
  2. On Epic creation, copy field Key to field "Dummy"
  3. On Epic transition, clone issue as Task
  4. On Task creation (inside the Task workflow), copy field "Dummy" to field "Epic Link"

 

I'm getting this error when looking at the Epic after I do this, so setting the field Epic Link requires something specific which I don't know about. The issue Key is not good enough.

 

EDIT: This actually works, just be careful to set the Copy Field to Field post-function AFTER the issue is created.

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 8, 2016

"I'm getting this error when looking at the Epic after I do this" - Do you mean Task or Epic?

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 8, 2016
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 8, 2016

"This will exit the Creation process and leave an inconsistency on issues. Make sure the "Creates the issue originally." Post Function is first in the Create transition."

Ovidiu Vasilescu August 8, 2016

Right, that was a bit embarrassing. Well I'm happy to say that with this dirty workaround (and having the "Copy link from "Dummy" to "Epic Link"" AFTER the issue was created) it works.

And it gracefully fails for other situations (such as when someone creates one manually).

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 8, 2016

nice to hear, could you please accept or upvote my answer. thanks.

 

1 vote
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 8, 2016

Please see here - https://answers.atlassian.com/questions/211505

issue.setCustomField might not be right

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 8, 2016

the same thing here - https://answers.atlassian.com/questions/13418341 (answer by  user Dima Pasko )

 

Also, make sure that you have "Epic Link" issue added on the "Screens" of the issueTypes which are being cloned.

Ovidiu Vasilescu August 8, 2016

Epic Link is added on the Screen, that's not the problem.

Even though the first ticket wasn't about a post-function, it had a snippet of code that might be what I was looking for. I tried it and it didn't work:

import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Epic Link"}
def changeHolder = new DefaultIssueChangeHolder();
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), sourceIssue.key),changeHolder);

My coding skills are really not that strong and I'm really out of my league right now. I really don't understand why issue.setcustomfield = sourceissue.key doesn't work.

Epic Link is a custom field and it's expecting an issue key, so it should work, no?

 

Any help is appreciated.

Suggest an answer

Log in or Sign up to answer