The scenario is ...let say Task (parent) has three linked issues ie CR Task (standard type) ..so is all are the CR Task is in the same (Closed)status then the Task(parent) should transit to fully-deployed and any of the CR Task is not in closed status then the Task(parent) should transit to partially deployed.
We have written a script like below but it's not working as expected...
import java.util.Map;
import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collection;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkType;
import com.atlassian.jira.issue.link.LinkCollection;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.web.bean.PagerFilter;
import org.ofbiz.core.entity.GenericValue;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import com.atlassian.jira.workflow.JiraWorkflow;
import com.opensymphony.workflow.loader.ActionDescriptor;
import com.atlassian.jira.issue.MutableIssue;
MutableIssue myIssue = issue
Issue issue = issue;
if(issue != null)
{
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
boolean flag = false;
int count = 0;
System.out.println("@@ Issue Status is : "+issue.getStatus().getName());
List<IssueLink> links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
System.out.println("@@ Issue Links is : " +links);
for (final IssueLink link : links)
{
final String name = link.getIssueLinkType().getName();
final Issue destinationObject = link.getDestinationObject();
//Looking for Application Release
if(destinationObject.getIssueType().getName().equalsIgnoreCase("Task"))
{
List<IssueLink> application_linked_ticket = ComponentAccessor.getIssueLinkManager().getOutwardLinks(destinationObject.getId());
System.out.println("@@@@@@ Destination object type : " +destinationObject.getIssueType().getName());
for (final IssueLink appLink : application_linked_ticket)
{
final Issue linkedTicket = appLink.getDestinationObject();
if(linkedTicket.getIssueType().getName().equalsIgnoreCase("CR Task") && !(issue.equals(linkedTicket)))
{
count++;
// Status Fully Deployed
if(linkedTicket.getStatus().getName().equalsIgnoreCase("In Progress"))
{
flag = true;
}
else
{
flag = false;
break;
}
}
}
// Transition to Fully Deployed
if(flag || count ==0)
{
System.out.println("@@@@@ fully Destination Object Status is : " + destinationObject.getStatus().getName());
JiraWorkflow workFlow = ComponentAccessor.getWorkflowManager().getWorkflow(destinationObject);
System.out.println("@@@@@@@@ Workflow for fully @@@@@@@@@@ : " + ComponentAccessor.getWorkflowManager().getWorkflow(destinationObject));
com.opensymphony.workflow.loader.StepDescriptor currentStep = workFlow.getLinkedStep(destinationObject.getStatus());
List<ActionDescriptor> actions = currentStep.getActions();
for(ActionDescriptor action : actions)
{
System.out.println("@@@@@ Action for fully is : " + action.getId());
if(action.getId() == 41)
{
boolean result = false;
IssueService issueService = ComponentAccessor.getIssueService();
IssueService.IssueResult transResult;
IssueInputParameters issueInputParameters = new IssueInputParametersImpl();
TransitionValidationResult validationResult = issueService.validateTransition(user, destinationObject.getId(), action.getId(), issueInputParameters);
result = validationResult.isValid();
if(result)
{
transResult = issueService.transition(user, validationResult);
}
}
}
}
else //tranistion to partially deployed
{
System.out.println("@@@@@ partially Destination Object Status is : " + destinationObject.getStatus().getName());
JiraWorkflow workFlow = ComponentAccessor.getWorkflowManager().getWorkflow(destinationObject);
System.out.println("@@@@@@@@ partially Workflow @@@@@@@@@@ : " + ComponentAccessor.getWorkflowManager().getWorkflow(destinationObject));
com.opensymphony.workflow.loader.StepDescriptor currentStep = workFlow.getLinkedStep(destinationObject.getStatus());
List<ActionDescriptor> actions = currentStep.getActions();
for(ActionDescriptor action : actions)
{
System.out.println("@@@@@ Action for partially is : " + action.getId());
if(action.getId() == 11)
{
boolean result = false;
IssueService issueService = ComponentAccessor.getIssueService();
IssueService.IssueResult transResult;
IssueInputParameters issueInputParameters = new IssueInputParametersImpl();
TransitionValidationResult validationResult = issueService.validateTransition(user, destinationObject.getId(), action.getId(), issueInputParameters);
result = validationResult.isValid();
if(result)
{
transResult = issueService.transition(user, validationResult);
}
}
}
}
}
}
System.out.println("@@ Issue Links For bloack");
}
Finally, we get this script done...
import java.util.Map;
import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collection;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkType;
import com.atlassian.jira.issue.link.LinkCollection;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.web.bean.PagerFilter;
import org.ofbiz.core.entity.GenericValue;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import com.atlassian.jira.workflow.JiraWorkflow;
import com.opensymphony.workflow.loader.ActionDescriptor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.link.LinkCollection;
MutableIssue myIssue = issue
int count = 0;
if(issue != null)
{
System.out.println("@@ Script Started @@");
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
boolean flag = false;
List<IssueLink> links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
Collection<Issue> allLinkedIssues = null;
LinkCollection linkedIssues = ComponentAccessor.getIssueLinkManager().getLinkCollectionOverrideSecurity(issue);
if(linkedIssues != null)
{
allLinkedIssues = linkedIssues.getAllIssues();
}
for(Issue ticket : allLinkedIssues)
{
System.out.println(" @@@@@@ Enter into For Loop ")
final Issue destinationObject = ticket;
//Looking for Application Release
if(destinationObject.getIssueType().getName().equalsIgnoreCase("Task"))
{
Collection<Issue> allIssues = null;
Set<IssueLinkType> allLinkTypes = null;
System.out.println("@@ Found Task issue type : " +destinationObject.getKey() + " : " +destinationObject.getIssueType().getName());
LinkCollection test = ComponentAccessor.getIssueLinkManager().getLinkCollectionOverrideSecurity(destinationObject);
if(test != null)
{
allIssues = test.getAllIssues();
allLinkTypes = test.getLinkTypes();
}
for(Issue temp:allIssues)
{
System.out.println("@@ Found Ticket : " +temp.getKey() + " : " +temp.getIssueType().getName());
if(temp.getIssueType().getName().equalsIgnoreCase("CR Task") && !(issue.equals(temp)))
{
count++;
// Status Fully Deployed
if(temp.getStatus().getName().equalsIgnoreCase("In Progress"))
{
flag = true;
}
else
{
flag = false;
break;
}
}
}
// Transition to Fully Deployed
if(flag || count==0)
{
System.out.println("@@@@@ Destination Object Status is : " + destinationObject.getStatus().getName());
//flag = true;
JiraWorkflow workFlow = ComponentAccessor.getWorkflowManager().getWorkflow(destinationObject);
System.out.println("@@@@@@@@ Workflow @@@@@@@@@@ : " + ComponentAccessor.getWorkflowManager().getWorkflow(destinationObject));
com.opensymphony.workflow.loader.StepDescriptor currentStep = workFlow.getLinkedStep(destinationObject.getStatus());
List<ActionDescriptor> actions = currentStep.getActions();
for(ActionDescriptor action : actions)
{
if(action.getId() == 11)
{
boolean result = false;
IssueService issueService = ComponentAccessor.getIssueService();
IssueService.IssueResult transResult;
IssueInputParameters issueInputParameters = new IssueInputParametersImpl();
TransitionValidationResult validationResult = issueService.validateTransition(user, destinationObject.getId(), action.getId(), issueInputParameters);
result = validationResult.isValid();
if(result)
{
transResult = issueService.transition(user, validationResult);
}
}
}
}
else //tranistion to partially deployed
{
System.out.println("@@@@@ Destination Object Status is : " + destinationObject.getStatus().getName());
//flag = true;
JiraWorkflow workFlow = ComponentAccessor.getWorkflowManager().getWorkflow(destinationObject);
System.out.println("@@@@@@@@ Workflow @@@@@@@@@@ : " + ComponentAccessor.getWorkflowManager().getWorkflow(destinationObject));
com.opensymphony.workflow.loader.StepDescriptor currentStep = workFlow.getLinkedStep(destinationObject.getStatus());
List<ActionDescriptor> actions = currentStep.getActions();
for(ActionDescriptor action : actions)
{
if(action.getId() == 11)
{
boolean result = false;
IssueService issueService = ComponentAccessor.getIssueService();
IssueService.IssueResult transResult;
IssueInputParameters issueInputParameters = new IssueInputParametersImpl();
TransitionValidationResult validationResult = issueService.validateTransition(user, destinationObject.getId(), action.getId(), issueInputParameters);
result = validationResult.isValid();
if(result)
{
transResult = issueService.transition(user, validationResult);
}
}
}
}
}
}
System.out.println("@@ Script Ended @@");
}
We are looking to implement something similar. How did you apply this script was it via a listener? Can you provide details on how it was implemented?
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to aad the post function with the script to the linked issue transition..not required to write/add to the listener.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Yogesh Mude - Hi Yogesh,
I have a similar requirement, could you please help me on this.
Automatically change status on a parent issue based on the status of its linked issue statuses when a linked issue status is CLOSED
We have Release Workflow -
Open - Development - QA Deployment - UAT - Deployment - Production
Scheduled Deployment Workflow -
Open - In progress - Deployment - Closed
Once the Release issue type is progressed to "QA Deployment" then the QA: Scheduled_Deployment task will auto create.
And the Release issue type is progressed to "Deployment" then Prod: Scheduled_Deployment task will auto create.
Now the Requirement is - Once the QA: Scheduled_Deployment task closed then the Release issue type status automatically change as "UAT"
Once the Prod: Scheduled_Deployment task closed then the Release issue type status automatically change as "PRODUCTION"
Note: We are using Script Runner for JIRA v5.2.1 and JIRA Server v7.3.6
Please help me with a script to achieve this as am new to script runner.
Regards,
Prasad
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.