Forums

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

Need to set the values in parent object from linked issues

Suvidhaa Subramani November 22, 2022

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. 

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 26, 2022

Hi @Suvidhaa Subramani

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:-

listener_configuration.png

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.

sub_task_before_link.png

bug_issue_before_link.png

2. Next, the Sub-task is edited, and a link to the Bug issue is added, as shown in the screenshot below:-

sub_task_linking_bug.png

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.

sub_task_after_link.png

bug_issue_after_link.png

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

Suggest an answer

Log in or Sign up to answer