how to do workflow transitions through custom script post function based on conditions

Mamta Verma August 2, 2018

I have 2 workflows: Capability_WF  and Feature_WF.

There are two issues F1 and F2 associated to Feature_WF and one issue C1 associated to Capability_WF , where F1, F2 are child of C1.

So when

1) F1 status moves to COMMITTED, F2 status moves to any status other than COMMITTED---> C1 status should move to PARTIAL COMMITTED (because both the child f1 n f2 are not committed yet)

2) F1 status moves to COMMITTED, F2 status moves to COMMITTED---> C1 status should move to COMMITTED.

how can I achieve this through custom script post function?

I'm trying out somthing like below:

import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.config.SubTaskManager;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def linkType = ["Parent Link"]
def passesCondition = true
def linkMgr = ComponentAccessor.getIssueLinkManager()
for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {
if (linkType.contains(link.issueLinkType.name)) {
if (! link.destinationObject.resolutionId) {
passesCondition = false

}
}
}
return passesCondition

// Get the details of the user executing the workflow transition for the issue change history
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller()
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class)

MutableIssue parent = issue.getIssueLink("Parent Link") as MutableIssue

// Get the status name of the parent issue
String originalParentStatus = parent.status?.name

def isParentTesting = originalParentStatus in ['IPD Signed Off']

// Update the issue by validating the transition can be completed first before executing it.
if (isParentTesting) {
workflowTransitionUtil.setIssue(parent)
workflowTransitionUtil.setUserkey(currentUser)
workflowTransitionUtil.setAction(131) // 131 is the ID of the Triage transition on the Story workflow
if (workflowTransitionUtil.validate()) {
workflowTransitionUtil.progress()
}
}

 

but before testing it I see an error on line:

MutableIssue parent = issue.getIssueLink("Parent Link") as MutableIssue

Error: com.atlassian.jira.issue.MutableIssue#getIssueLink(java.lang.String). Please check if the declared type is right and if the method exists.

Can someone help me this? Thanks

1 answer

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2018

Even if you fixed the error, it's going to fail - you can not perform a transition on an issue while it is in the middle of another transition.

Use a "fast track transition" instead.

Mamta Verma August 6, 2018

Thanks for the response. But I need to update the status of the parent issue(Workflow 1) based on the status of child/linked issue (workflow 2).

 

In fast track transition ,When I add a condition and try adding Action (in workflow 1 transition), it shows the transition/statuses of the same workflow in the Action dropdown. I dont see an option to include statuses of  child linked issue or vice versa.

Saurabh Zunke August 6, 2018

@Nic Brough -Adaptavist-: Hey Nic, thanks for your response.

I'm not sure if the requirement is clear so let me lay it out here again:

We have a two level Issue Type hierarchy for our use case.

Parent --> Child --> Grandchild 
(these are set up using Portfolio for JIRA so are separate Issue Types and not Sub-Tasks)

e.g.

A (Parent) --> B, C (Child)

B (Child) --> D, E (Grandchild)

C (Child) --> F, G (Grandchild)

We want to cascade status updates from the Grandchild level all the way up to Parent level. i.e. If one or more grandchild moves from NEW to IN-PROGRESS, the parent automatically moves from NEW to IN-PROGRESS - applicable across all hierarchies

Considering this example, details are as follows:

a) When D or E moves from NEW to IN-PROGRESS, its Parent B will move from NEW to IN-PROGRESS and furthermore its own parent A will move from NEW to IN-PROGRESS

b) When D & E both move from IN-PROGRESS to COMPLETE, its Parent B will move from IN-PROGRESS to COMPLETE

c) When all D, E, F & G are COMPLETE, and their Parents B & C will be COMPLETE and furthermore, the Grandparent A will move from IN-PROGRESS to COMPLETE

I hope this helps clarify our requirement.
Thanks in advance for your help!

Suggest an answer

Log in or Sign up to answer