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"
}
Hi Amy,
You've almost nailed it. Here's the correct way:
import com.atlassian.jira.issue.Issue
Issue parent = issue.getParentObject()
List<Issue> otherSubtasks = parent.getSubTaskObjects().findAll{it.getIssueType().getName().equals("Estimate")}
return otherSubtasks.every{it.getStatus().getName().equals("Final")}
Hi Ivan, thanks for your help! I've tried this but getting an error:
[Static type checking] - Cannot assign value of type java.util.Collection <com.atlassian.jira.issue.Issue> to variable of type java.util.List <Issue>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can pretty much ignore this error. It'll work just fine as is. Thing is static type checking in Scriptrunner is not always accurate.
However if you wanna get rid of this error simply change "List" to "Collection" in the code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, thanks for that. I'm getting this error and I think it's because the siblings are not subtasks? I mistakenly assumed that any child was a subtask but these siblings are tasks which is why this if failing:
Cannot invoke method getSubTaskObjects() on null object at Script748.run(Script748.groovy:4)
I definitely have siblings of that issue type within the same Epic so I'm not sure why it would be null unless it has to do with them not being subtasks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Indeed,
This error occurs because the issue this script is executed in is NOT a subtask and as such does not have a "parent". That's why the parent here is null, hence the error.
Now that we have this out of the way, I think I can still help you with this, but first could you clarify what exactly do you mean by "siblings"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure. I have the following hierarchy:
Epic
-Estimate issue type (task)
-Intake issue type (task)
-Job issue type (task)
My objective is to prevent the Job task from being put into IN PROGRESS state if the Estimate and Intake are not in the DONE state. So I've set this condition on the Job issue type, though it might be better practice to put is as a validator.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Condition is the correct approach here. Make sure you put it on your transition that leads to "In Progress" status.
The code is as follows:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Logger log = LoggerFactory.getLogger("LOG")
CustomFieldManager cfMgr = ComponentAccessor.getCustomFieldManager()
def epicLinkMgr = getBean("epicLinkManagerImpl")
Issue epic = issue.getCustomFieldValue(cfMgr.getCustomFieldObjectByName("Epic Link")) as Issue
log.error("Epic issue: ${epic.getKey()}")
List<String> issueTypeList = Arrays.asList("Estimate", "Intake")
List<Issue> issuesInEpic = epicLinkMgr.getIssuesInEpic(epic).findAll{issueTypeList.contains(it.getIssueType().getName())}
log.error("Issues to check: ${issuesInEpic.toString()}")
log.error("Issue statuses: ${issuesInEpic.collect{it.getStatus().getName()}.toString()}")
return issuesInEpic.every{it.getStatus().getName().equals("Done")}
def getBean(String beanId){
def ghPlugin = ComponentAccessor.getPluginAccessor().getEnabledPlugin("com.pyxis.greenhopper.jira")
def descriptor = ghPlugin.getModuleDescriptor("greenhopper-launcher")
def applicationContext = descriptor.getModule().greenHopperCacheManager.applicationContext
def beanInstance = applicationContext.getBean(beanId)
return beanInstance;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately, still allowing me to transition to In Progress despite both Estimate and Intake not sitting in Done. Is there any way to find out what's allowing that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just to clarify, your Intake and Estimate issues are connected to an epic via "epic link" field and not a simple issue link, right?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, here's a screen grab showing that we have both the Estimate and the Intake tasks within "Issues in Epic" as well as the new task that I'm trying to prevent the "OK to Begin" transition: https://screencast.com/t/GmGb0MsI
I put the script on a Condition on the "OK to Begin" transition within the Task workflow as shown here: https://screencast.com/t/JVh3ojC3nP.
However, it's still showing as an option when the other two are not Done: https://screencast.com/t/bwQzf9KFx
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's odd. I've added some logging to the code above to be able to see what exactly is going on there. Could you please update your code with it and send me a screenshot of your script logs.? To quickly get to them, open your conditions tab and click on the last green ckeckmark (or red X) in your scripted condition. Make sure the code is executed after the update before your check the logs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, here's the log:
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2018-10-02 14:52:40,266 ERROR [LOG]: Epic issue: AMGNLUS-58 2018-10-02 14:52:40,294 ERROR [LOG]: Issues to check: [AMGNLUS-59, AMGNLUS-60] 2018-10-02 14:52:40,295 ERROR [LOG]: Issue statuses: [IN PROGRESS, TO DO]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, so we know that we are getting the correct issues and we are getting their statuses right. The problem seems to be in 'return' statement. Try chaning it to:
return issuesInEpic.every{it.getStatus().getName().equalsIgnoreCase("Done")}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your help, Ivan. But unfortunately, it's still allowing me to push this task. Can you clarify what part of this script disables the transition?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The script should return logical true for the transition to become available or logical false otherwise. The 'return' statement does that in this case.
'every' closure returns true if the condition inside the closure is true for every element of the 'issuesInEpic' list.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Interesting: I just tried running it as a validator and it seems to work as intended.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Marked this as answered but want to clarify that this worked as a Validator rather than a Condition for me.
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.