Hi, I'm looking to create a condition on a transition that is dependent on whether or not siblings of a certain issue type are in a particular status.
I've found a solution from 2016 but code has since been deprecated.
def parent = issue.parentObject
def otherSubtasks = parent.subTaskObjects.findAll { it.issueTypeObject.name in ["A", "B"]}
return otherSubtasks.every {
it.statusObject.name == "Resolved"
}
Now we are supposed to use getIssueType() and getStatus().
Two questions:
I know this is wrong but wanted to show I tried:
import com.atlassian.jira.issue.Issue
def parent = issue.parentObject
def otherSubtasks = parent.subTaskObjects.findAll { issue.issueType.name == "Estimate"}
return otherSubtasks.every {
otherSubtasks.getStatus() = "Final"
}
Hello Mike.
If you want to see, there some just done scripts in Groovy for this your requirement specifically to work with custom fields in tasks (like time spent or whathever) and sub-tasks and native fields in Jira.
You can look at: https://github.com/GTessarini/JiraAutomations
I hope help you!
Regards
Gabriel Tessarini
Thanks @Gabriel Tessarini, I'll have a look. That wasn't some of what popped up when I was grepping Google for guidance (and is one of the next iterations that I'll be mucking about with)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Gabriel Tessarini, I accepted YOUR answer as well as that addresses my next iteration on this festival. Much appreciated
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Mike Rathwell
The thing is, that method getParentObject() returns Issue object, that is immutable class and doesnt have set methods. So you need to get MutableIssue first, like this. And do not forget to update issue to store changes.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import java.sql.Timestamp;
import java.util.Date.*
def issueManager = ComponentAccessor.getIssueManager();
def startDateField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11014");
def endDateField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11015");
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Issue sourceIssue = issueManager.getIssueObject("ITPROJECTS-295");
MutableIssue parentIssue = issueManager.getIssueObject(sourceIssue.getParentObject().getKey())
def parentStartDate = parentIssue.getCustomFieldValue(startDateField)
def parentEndDate = parentIssue.getCustomFieldValue(endDateField)
Date startResult = null
Date endResult = null
def startResultTimeStamp
def endResultTimeStamp
Collection subTasks = parentIssue.getSubTaskObjects();
for(subtask in subTasks) {
def subTaskStartDate = subtask.getCustomFieldValue(startDateField) as Date
def subTaskEndDate = subtask.getCustomFieldValue(endDateField) as Date
if (startResult == null || (subTaskStartDate < startResult)){
startResult = subTaskStartDate
}
if (endResult == null || (subTaskEndDate > endResult)){
endResult = subTaskEndDate
}
}
if (parentStartDate != startResult && parentEndDate != endResult)
// return "${startResult} - ${endResult} for ${parentIssue} having Start ${parentStartDate} and End ${parentEndDate}"
parentIssue.setCustomFieldValue(parentStartDate, startResultTimeStamp)
issueManager.updateIssue(user, parentIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, @Mark Markov. I'll give that a shot. Please ignore some of the other detritus in that script as it is full of debuggish/try this crap.
Question - should i push a timestamp or a date into the CF? I can do either; use date for the compares (lazy, i know but works) and timestamp to populate the field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Mark Markov That was exactly the ticket. I tried Mutable BUT thinking back, I declared it wrong. You solved this issue for me
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mark Markov can you please help me in writing a script where , when subtask custom field gets updated same should reflect in parent task aslo.
Looking forward to your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @[deleted] , I don't know if you already have help in your project, but in my code repository for this Jira Automations, I have some scripts that may be applied to your need. Check it out:
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.