Can we prevent transition of subtask based on linked (subtask)issue status in jira?
We have button on subtask to change transition but I want to put validation here.
Prevent transition if linked issues are not yet approved.
Is it possible?
Sure you can create complex validations.
Take a look at the free plugin https://marketplace.atlassian.com/apps/575829/workflow-enhancer-for-jira. There you'll find a lot of conditions to use in your workflows.
You might need to use some sort of calculated field, or my prefered option a SIL custom field, to calculate something those conditions themselves can't calculate and then use that value to trigger the condition or not.
If you haven't come across SIL custom fields yet, they come with https://marketplace.atlassian.com/apps/1210749/power-custom-fields-for-jira. I believe you don'e need to purchase the license just to use the SIL custom fields, at least up until some version, but if you think you're going to make extensive use of this it would be adviseable to unlock the full potential of the pugin. In any case check it out.
Hope it helps
Actually, We have two workflows.
1. Approvals workflow : In the post function of approval's workflow what we have implemented, when we approve all the approval subtasks then the status of ITRequest(linked to approval subtasks) will be automatically changed to "scheduled" state.
2. ITPS workflow : But when we manually click on the Schedule button on "ITRequest" subtask, then it's state changed to "schedule". So I need to put validation here : should not change to "scheduled" state until and unless all the approvals sub task got approved.
So What kind of validation we need to implement here.
Please suggest.
You have just described the validation you need!
Go ahead and try the plugins I've talked you about.
From the top of my head I would use a SIL custom field to check if the number of subtasks of a given issue is equal to the number of APROVED subtasks of the issue. You could then use that field as the condition to enable or even execute the transitions you describe.
Yes, you are right.
I have implemented this as you said but I have one doubt.
Please see my code below:
import groovy.xml.MarkupBuilderimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.config.properties.APKeysimport com.atlassian.jira.issue.link.LinkCollectionImpl;import com.atlassian.jira.issue.link.IssueLink;import com.atlassian.jira.component.ComponentAccessor;import org.apache.log4j.Categoryimport org.apache.log4j.Loggerimport org.apache.log4j.Levelimport com.atlassian.jira.workflow.WorkflowTransitionUtil;import com.atlassian.jira.util.JiraUtils;import com.atlassian.jira.issue.MutableIssue;import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;import com.opensymphony.workflow.WorkflowContext;
def Category log = Category.getInstance("com.innovalog.jmwe.plugins.functions.CommentIssueFunction")log.setLevel(org.apache.log4j.Level.DEBUG)log.debug "Scheduled Condition"log.info("started Condition");
def approvalIssuesCount = 0;def approvedStatusCount = 0;MutableIssue parentIssue = issue as MutableIssueList<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());for (Iterator<IssueLink> outIterator = allInIssueLink.iterator(); outIterator.hasNext();) {IssueLink issueLink = (IssueLink) outIterator.next();;
MutableIssue linkedIssue = issueLink.getSourceObject() as MutableIssueString type = linkedIssue.getIssueType().getName();log.info("linkedIssue" + linkedIssue);
if(type.equals("Approval")){approvalIssuesCount++;String linkedIssueStatus = linkedIssue.getStatus().getName();if(linkedIssueStatus.equals("Approved")){approvedStatusCount++;}log.info("linked issues Approval Status******************* : " + linkedIssueStatus);}}log.info("approvalIssuesCount : " + approvalIssuesCount);log.info("approvedStatusCount : " + approvedStatusCount);if(approvalIssuesCount != approvedStatusCount ){ // what I need to write here}
if(approvalIssuesCount == approvedStatusCount ){ // what I need to write here}
It looks like you're new here. Sign in or register to get started.