Forums

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

Transition main issue to "Open" automatically when all linked issues are closed

Swarna Radha
Contributor
August 19, 2019

Hi,

 

I am using the script below to do the transition to "Open" when all linked issues are closed.

After execution, main ticket remains to escalated to supplier instead to Open.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
import org.apache.log4j.Category
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.MutableIssue

log.setLevel(org.apache.log4j.Level.DEBUG)

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
log.debug "Original: ${issue.getId()}, ${issue.getKey()}. DETECTED " + issue.getStatus().name

List<IssueLink> allInIssueLink = issueLinkManager.getInwardLinks(issue.getId());
for (Iterator<IssueLink> inIterator = allInIssueLink.iterator(); inIterator.hasNext();) {
IssueLink issueLink = (IssueLink) inIterator.next();
def linkedIssue = issueLink.getDestinationObject();
log.debug "linked: ${linkedIssue.getId()}, ${linkedIssue.getKey()}. DETECTED " + linkedIssue.getStatus().name
if (linkedIssue.getStatus().name.equals("Open")) { // STATO della issue collegata
log.debug "linked Content: ${linkedIssue.getId()}, ${linkedIssue.getKey()}."

//We can transition the parent ticket
log.debug "start transition"

workflowTransitionUtil.setIssue((MutableIssue) linkedIssue);
workflowTransitionUtil.setUserkey(currentUser);
workflowTransitionUtil.setAction (221); //Transition ID
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();

log.debug "end transition"
}

}

 

Kindly advice.

 

Thanks,

Swarna

2 answers

0 votes
Radu
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 21, 2019

ok, so I'm not sure this script will get you what you want with minor fixes.

Looking at your current script

issueLinkManager.getInwardLinks(issue.getId());

returns only the original issue in the list, not the issue it's liked to. 

I'm not sure how issue links are defined on your instance so you might be able to fix this by using 

Check the documentation on https://docs.atlassian.com/software/jira/docs/api/7.1.7/com/atlassian/jira/issue/link/IssueLinkManager.html#getInwardLinks-java.lang.Long- vs https://docs.atlassian.com/software/jira/docs/api/7.1.7/com/atlassian/jira/issue/link/IssueLinkManager.html#getOutwardLinks-java.lang.Long-

issueLinkManager.getOutwardLinks(issue.getId());

And if you have only 1 issue linked to it you should get the parent/central one you would like to modify.

However this is not enough as you might have a parent issue with more than one linked issue and this would work only if you had 1 linked issue.

The script needs to be modified to:

1. find the "parent" issue linked with the one that was transitioned

2. get all the linked issued of the parent and check they are all closed

3. execute the query for the issue you want.

Currently 

1. is not working because you're getting the same original issue

2. "parent" level checks are not present in the script.

3. should work.

 

Hope this helps you on the right path.

 

Cheers,
Radu

Swarna Radha
Contributor
August 21, 2019

Can you provide me the script. Am not doing at scripting :(

Thanks

0 votes
Radu
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 20, 2019

hi @Swarna Radha ,

Sounds a bit complicated, why don't you use automation and configure the automated transition of the parent ticket once all linked tickets reached a "Done" state.

Screen Shot 2019-08-20 at 5.39.38 pm.png

 

Let me know if this works for you.

Cheers,

Radu

Swarna Radha
Contributor
August 20, 2019

Hi,

I have used automation rule before scripting, it does not check if all linked issues are closed. If One linked issue is closed, issue is transitioned to Open. But all the remaining linked issues are still opened

Radu
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 21, 2019

Hi @Swarna Radha ,

Looking through the code I see:

...

if (linkedIssue.getStatus().name.equals("Open")) {

...

I understand that means "If the linked issue is in status Open then" do the transition 221. 

I think you could remove the condition if you want to transition all the issues through transition 221

 

Cheers,

Radu

Swarna Radha
Contributor
August 21, 2019

Hi Radu,

 

I have removed the condition. When I run the script. In the log it said the following:

2019-08-22 08:28:28,375 DEBUG [workflow.ScriptWorkflowFunction]: Original: 148363, CM-222. DETECTED Closed
2019-08-22 08:28:28,376 DEBUG [workflow.ScriptWorkflowFunction]: linked: 148363, CM-222. DETECTED Closed
2019-08-22 08:28:28,376 DEBUG [workflow.ScriptWorkflowFunction]: linked Content: 148363, CM-222.
2019-08-22 08:28:28,376 DEBUG [workflow.ScriptWorkflowFunction]: start transition
2019-08-22 08:28:28,380 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-08-22 08:28:28,381 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CM-222, actionId: 11, file: <inline script>
java.lang.IllegalArgumentException: No workflow action with id '221' available for issue CM-222

 

I have added the script in the linked issue in the closed transition. When it closes, it transitions the main ticket 

Radu
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 21, 2019

 

HI,

 

If the issue is CM-222 how can the linked issue be also CM-222 ?


I'd try to run it on my instance. Are you using Script Runner for this?

 

Thanks,

Radu

Swarna Radha
Contributor
August 21, 2019

CM- 222 is linked to main ticket.

My scenario is that when agent clicks on escalated to supplier, a linked issue is created ( Supplier Task). When all supplier tasks are closed, the main ticket should transition from escalated to supplier to "Open". 

I have added the code on close transition of the supplier task.

workflowTransitionUtil.setAction (221); //Transition ID- this is the transition of the main ticket from escalated to supplier to open.

I am using script runner.

Thanks,

Swarna

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events