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
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i have a requirement some how your type only.
Did you find any solution till date?
Regards
Manas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.