Forums

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

How to find specific related issue using Groovy scripting in Post Function

Vivienne Barrett
November 11, 2020

Hi there, 

I need to set a specific value on a custom field within some linked issues but not all of them. 

I'm using the 'Set field value of related issues (JMWE app)' Post Function and am using the 'Issues Returned by the following Groovy script' option to find the specific related issues that I require updated. 

From the research I've carried out to date the following syntax returns a list of all of the related issues 

issue.getLinkedIssues()

And these are the results:

Result type:
ArrayList
Result value:
[Test-250, Test-249]

So this gives me all the related links which is great but I need to break that down further and only have the 'Result Value = Test-249' and not just list all of the related issues. 

Is this doable? Does anyone have the correct syntax to use in this scenario? 

Any help appreciated... 

Thanks

 

2 answers

1 accepted

1 vote
Answer accepted
Fabio Racobaldo _Catworkx_
Community Champion
May 4, 2014

Hello Kyle,

you could specify the following script into your transition:

import java.util.Collection;

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.status.Status;
import com.atlassian.jira.workflow.JiraWorkflow;
import com.atlassian.jira.workflow.WorkflowManager;
	
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager();
Issue issue = issue;
		
Collection<Issue> subtasks = issue.getSubTaskObjects();
for(Issue sub : subtasks){
	JiraWorkflow workflow = workflowManager.getWorkflow(sub);
	Collection<Status> statuses = workflow.getLinkedStatusObjects();
	Status destStatus = null;
	for(Status status : statuses){
		if(status.getName().equalsIgnoreCase("YOUR FINAL STATUS HERE")){
			destStatus = status;
			break;
		}
	}
	workflowManager.migrateIssueToWorkflow((MutableIssue)sub, workflow, destStatus);
}

Please, specify your final status first.

Hope this helps,

Fabio

0 votes
Kyle Ortiz
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 4, 2014

I did some changes on the provided script and it works well. thanks so much Fabio

Suggest an answer

Log in or Sign up to answer