Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem updating field on story when epic link changes

Eric Lakey April 10, 2019

I am trying to populate a field on the story if certain conditions are met on the epic linked to that story.  This works great with a ScriptRunner custom listener on the IssueUpdated event.  EXCEPT when the update to the issue is changing the actual epic.  When my script looks up the values on the Epic it is referencing the old value of the epic instead of the new value.  How can I make sure this script fires after the epic link update has taken effect or make sure my script references the changed value and not the original value?

 

Here is my script:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItemImpl
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.util.ImportUtils


CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager()
def issue = event.issue as Issue
//Issue issue = issueManager.getIssueObject("DEV-8167"); //Company Rock

//Prepare target field for update
def RockWorkField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Rock Work"}
def RockWorkFieldConfig = RockWorkField.getRelevantConfig(issue)
def YesValue = ComponentAccessor.optionsManager.getOptions(RockWorkFieldConfig)?.find { it.toString() == 'Yes' }
def NoValue = ComponentAccessor.optionsManager.getOptions(RockWorkFieldConfig)?.find { it.toString() == 'No' }

def changeHolder = new DefaultIssueChangeHolder()
def newRockWorkValue

// Check if Issue Type is Story
def IssueType = issue.getIssueType().getName()
if (IssueType == "Story" || IssueType == "Bug") {

// Get Custom Field as string (Epic Link)
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")

// Get Custom Field Value as String
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
String EpicName = issue.getCustomFieldValue(epicLink);

if(EpicName){
// Get Epic from Issue
def epicIssue = issue.getCustomFieldValue(epicLinkCf) as Issue

// Get Rock Level from Epic
CustomField RockLevelField = customFieldManager.getCustomFieldObjectByName('Rock Level');
String RockLevel = epicIssue.getCustomFieldValue(RockLevelField);

if(RockLevel == "Company" || RockLevel == "Implementation")
newRockWorkValue = YesValue //Company rock or Imp rock
else
newRockWorkValue = NoValue //Not company or imp rock
}
else newRockWorkValue = NoValue //No Epic on story

RockWorkField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(RockWorkField), newRockWorkValue),changeHolder)

}

return newRockWorkValue

2 answers

1 accepted

0 votes
Answer accepted
PD Sheehan
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.
April 10, 2019

I tried to do something similar a year or 2 ago... and at the time, I think I found that changing the Epic Link didn't fire an IssueUpdated event... or any event for that matter.

I think there was a ticket for this, and I think a recent newer version includes more events, but I haven't tested yet if that was one of them.

Eric Lakey April 11, 2019

Thanks Peter-Dave.  You've got me headed in the right direction.  Now I'm trying to figure out how to use the IssueLinkCreatedEvent and IssueLinkDeletedEvent.  I'll post more if I figure this out.

Dave F
Contributor
November 20, 2019

Not firing an event when an issue is added or removed from an Epic when using the drag and drop feature in the Backlog view seems a massive flaw that needs fixing. It's a rather important update to the issue.

I don't see ScriptRunner as an acceptable work around either. Admins should not have to learn a new coding language to fix holes in a vendor's solution. Isn't that the vendor's developer's job?

On a brighter note, has anyone found a solution that can be easily/totally described and transferred through this forum? 

0 votes
J Manas Kumar
Contributor
March 13, 2020

@Eric Lakey

@Eric Lakey  

i have a requirement some how your type only.

Did you find any solution till date?

 

 

Regards

Manas

Eric Lakey March 13, 2020

@J Manas Kumar - I would look at this thread. I was close to getting it to work but then my problem changed so I never finished it.  But I think this thread is the right path to solve it.  https://community.atlassian.com/t5/Jira-questions/How-to-get-current-issue-when-I-use-IssueLinkCreatedEvent-event/qaq-p/879597

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events