Hi,
I have a Bug linked to Sub task.
In Sub-task, i have Custom field A and Custom field B. I have created a Bug and linked it to sub-task with linktype as "blocks". Is there a way, we can set the linked sub-task custom field values in Bug?
I need to filter the bugs which is linked to subtask which has the custom field A value = xxx
Could you please help me in this. We have script runner plugin also.
For your requirement, it would be best if you used the ScriptRunner Listener along with the IssueLinkCreated event.
Below is a sample working code for your reference:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueLinkCreated = event as IssueLinkCreatedEvent
def issueLink = issueLinkCreated.issueLink
def destinationIssue = issueLink.destinationObject as MutableIssue //is blocked by
def sourceIssue = issueLink.sourceObject as MutableIssue //blocks
def sampleText = customFieldManager.getCustomFieldObjectsByName('Sample Text').first()
def sampleTextValue = destinationIssue.getCustomFieldValue(sampleText) as String
def sampleText2 = customFieldManager.getCustomFieldObjectsByName('Sample Text 2').first()
def sampleText2Value = destinationIssue.getCustomFieldValue(sampleText2) as String
sourceIssue.setCustomFieldValue(sampleText, sampleTextValue)
sourceIssue.setCustomFieldValue(sampleText2, sampleText2Value)
issueManager.updateIssue(loggedInUser, sourceIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Listener configuration:-
Below are a few test screenshots for your reference:-
1. A Sub-task and a Bug ticket are created separately, as shown in the screenshots below. In this example, the Sub-task issue is a Sub-task to a Story. If you notice in the screenshot below, the text fields Sample Text and Sample Text 2 already have values for the Sub-task but not for the Bug.
2. Next, the Sub-task is edited, and a link to the Bug issue is added, as shown in the screenshot below:-
The is blocked by link is used for the Sub-task. Hence, the Bug issue will have the blocks link.
3. Once the link is added, the issues will be updated accordingly, as shown in the screenshots below. If you observe in the Sub-task issue, the is blocked by link is added. Similarly, the blocks link is added in the Bug issue, and the Sample Text and Sample Text 2 fields are updated in the Bug issue accordingly.
If you are to run the task in the reverse order, i.e. create the blocks link in the Bug issue, the result is the same.
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
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.