after multiple conditions are met then auto transition issue

Scott Federman May 20, 2019

I have an issue with multiple fields that must be selected to transition to the next status. How do i make it that if all fields a, b, and c = yes, as soon as the last of the three fields are moved to yes, then the issue auto transitions to the next status? These three fields can be filled out in any order but all three must = yes for the issue to move forward. 

1 answer

0 votes
Mike Rathwell
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.
May 20, 2019

Hi @Scott Federman ,

From the tags you put this on this question, it's likely you have the tools available to build this out. The Groovy script listener is going to be what you need. You'll want to watch for updates on that particular project and that particular issue type to see when the fields a, b, and c are updated. When any one or more of them are updated, validate if all three are "yes" and trigger the transition.

A key here will be that you need to validate all of the fields before deciding whether to transition. That said, there is a hole this could fall into where if all three are set to "yes" but then one is set to "no" after that, it'll already have made the transition. You may have to create an "oops" transition to put it back to the previous if one goes to "no" when one gets set no after the transition

Scott Federman May 21, 2019

Hey @Mike Rathwell , we just bought both power scripts and scriptrunner. I am however new to both of these and have no idea what I'm doing. :) Could you possibly help me out with what a groovy script might look like here? 

Mike Rathwell
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.
May 21, 2019

ok... here's one I use that updates the end date of an issue based on a change in the duration in days (and yes, there are other "simpler" ways to do this but I did have a use case and... request... There is lots of Groovy-ness in here to look at; iteration, subtasks, looking for the field that updated, etc... hope this is some grist for the thinking.

import java.sql.Timestamp;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkType;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.UpdateIssueRequest;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.event.issue.DelegatingJiraIssueEvent
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.IssueEventManager
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.issue.IssueEventBundleFactory
import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.issue.IssueManager
import java.text.DecimalFormat
DecimalFormat decimalFormat = new DecimalFormat();
IssueManager issueManager = ComponentAccessor.getIssueManager();
MutableIssue issue = issueManager.getIssueObject(event.issue.id) as MutableIssue;
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def startDateField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11014");
def endDateField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11015");
def durationField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_15403");
def newEndDate

List<HashMap<String, Object>> fieldsModified = event.getChangeLog()?.getRelated('ChildChangeItem') as List<HashMap<String, Object>>;
for (HashMap<String, Object> field : fieldsModified) {
if (event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field != "Task Duration"}) {
break
}

if (event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Task Duration"}) {
if (issue.getCustomFieldValue(durationField) == null) {
def changeHolder = new DefaultIssueChangeHolder()
endDateField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(endDateField), null), changeHolder)
issueManager.updateIssue(null, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
if (issue.getCustomFieldValue(durationField) != null) {
def endDateToSet = issue.getCustomFieldValue(endDateField)
Timestamp dateField = (Timestamp) issue.getCustomFieldValue(startDateField)
def duration = issue.getCustomFieldValue(durationField).toString()
int number = duration.toInteger() - 1
if (dateField) {
Date result = dateField;
Date setDate = new Date(result.getTime())
int i = 0 ;
while (i < number) {
result = result + 1
setDate = new Date(result.getTime())
if (setDate[Calendar.DAY_OF_WEEK] == Calendar.SATURDAY || setDate[Calendar.DAY_OF_WEEK] == Calendar.SUNDAY) {
number ++;
}
i ++;
}
newEndDate = result
if (endDateToSet != newEndDate) {
issue.setCustomFieldValue(endDateField, newEndDate)
}
}
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, true)
}
}
}

Suggest an answer

Log in or Sign up to answer