Hi,
Could somebody correct me with below script:
Create a user story, "Component" field should be empty.
Update Epic Link for user story, Component field should be copied from Epic to User Story. I am user Script listener with "issue updated" Event.
I have below script, could any one correct this 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
MutableIssue issue = (MutableIssue) event.issue;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager()
// Check if Issue Type is Story
if (issue.getIssueType().getName() == "Story" ) {
// 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 Component from Epic
def currentValue = epicIssue.getComponents()
// Set component to Story
issue.setComponent(currentValue)
}
}
Hi,
I did some similar things, but I never used the custom field Epic Link as it is not clear what kind of data type is in it. I guess that your "...getCustomFieldValue(...) as Issue" will for sure not work!
I used the link info instead to get the Epic issue:
import com.atlassian.jira.issue.link.IssueLinkManager
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getInwardLinks(event.issue.getId()).each {issueLink ->
if (issueLink.getIssueLinkType().getName() == "Epic-Story Link") {
Issue epicIssue = issueLink.getSourceObject()
}
}
In addition, I think you should also save the changes in your issue:
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
IssueManager issueManager = ComponentAccessor.getIssueManager()
ApplicationUser userId = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue (userId, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
(not dispatching update events further on as you might get in an endless loop)
Hope this helps
Hi Marc,
Thank you for your help.
I am still having issue in getting this work. If you don't mind, could you please paste the paste the complete script.
Sorry for troubling you more and thank you in advance.
Thanks,
Suresh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suresh,
The scrript is quite long and refers to a configuration (fields, workflows, ...) that is specific to our environment, so I think it is not very useful and will be difficult to understand.
Can you rather clarify what issues you still have ?
Marc
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.