Hi Community,
I want to hide a custom field present on Parent issue when the Parent issue is in Done status and all its Child issues (linked by Parent Link field) are in Done status as well.
Here, Parent issuetype = Initiative and Child issuetype = Portfolio Epic and I am using Parent-Child linking via Parent Link field.
How can we achieve this using scriptrunner behavior? Any sample code for reference would be a great help.
Thanks
Hi @Digvijay Singh Gehlot ,
If there is a parent-child relationship; then it is quite easy to solve that problem.
You need to:
Thus:
def theField = getFieldById("customfield_xxx")
if(underlyingIssue.status.name == "Done"){
def filteredSubtasks = underlyingIssue.subtasks.findAll { it -> it.issuetype.name == "Portfolio Epic" && it.status.name != "Done" }
if(filteredSubtasks.size() > 0){
theField.hidden = true
theField.formValue = null
}
else[
theField.hidden = false
theField.required = true
}
}
As an alternative, you may check by searching over JQL but I think the above code will work for you. Just don't forget to change the customfield's id.
Hi @Salih Tuç
Thank you for your message.
I tried to run your suggested code but unable to see the changes on the UI.
I refined the code as per my requirement as below:
def radioTypeField = getFieldById("customfield_XXXXX")
def parentIssueTypeName = underlyingIssue.issueType.name
def parentStatusName = underlyingIssue.status.name
// Using Advanced Roadmap hierarchy such as Portfolio Parent as Initiative and Portfolio Child as Portfolio Epic
if(parentIssueTypeName == "Initiative" && parentStatusName == "Repository"){
// All Portfolio Epic Children are linked with Initiative via Parent Link custom field instead of Subtasks
def childIssues = underlyingIssue.getSubTaskObjects().findAll
{
it -> it.issueType.name == "Portfolio Epic"
&& it.status.name == "Done" }
// Portfolio Epic Children can be one or more and are in Done status already
if(childIssues.size() > 0)
{
// Radio Type customfield should be editable and required
radioTypeField.readOnly = false
radioTypeField.required = true
}
else {
// Radio Type custom field should be in ReadOnly, Not required and set to None
radioTypeField.readOnly = true
radioTypeField.required = false
radioTypeField.formValue = null
}
}
I observed that, the code is showing Green but Radio Type custom field is still showing in ReadOnly mode on Parent issue although Parent is in Repository status and a Child (linked to Parent via Parent Link) is in Done status.
So, I have following questions below:
1) Parent issue is created in Parent project and Child issue is created in Child project. Will getSubTaskObjects() work with Parent Link field as used in above code?
2) Do I need to map both Parent and Child projects and their issue types in single behavior to fulfil the requirement?
Could you help me further with the above and it would be great if you can also share how JQL query is used within behavior script as an alternative to achieve my usecase.
For example: I have created a query which shows all those Parents where their Children are in Done status (and Parent Link is not empty)
Children Filter: project = CHILD AND status = "Done" AND "Parent Link" IS NOT Empty
JQL query:
project = PARENT AND issueFunction in portfolioParentsOf("filter = 'Children Filter'") AND status = "Repository"
I am looking forward to hearing from you soon.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The "Parent Link" is exactly states for Task/Story->Sub-task relationship; so yes it would work.
Remember that you should change the customfield_XXX with your field id (e.g customfield_12345). And also, you should place the script in initializer.
I think we forgot the outer else for the condition. Here is an updated code:
def radioTypeField = getFieldById("customfield_XXXXX")
def parentIssueTypeName = underlyingIssue.issueType.name
def parentStatusName = underlyingIssue.status.name
// Using Advanced Roadmap hierarchy such as Portfolio Parent as Initiative and Portfolio Child as Portfolio Epic
if(parentIssueTypeName == "Initiative" && parentStatusName == "Repository"){
// All Portfolio Epic Children are linked with Initiative via Parent Link custom field instead of Subtasks
def childIssues = underlyingIssue.getSubTaskObjects().findAll
{
it -> it.issueType.name == "Portfolio Epic"
&& it.status.name != "Done" }
// Portfolio Epic Children can be one or more and are in Done status already
if(childIssues.size() > 0)
{
// Radio Type customfield should be editable and required
radioTypeField.readOnly = false
radioTypeField.required = true
}
else {
// Radio Type custom field should be in ReadOnly, Not required and set to None
radioTypeField.readOnly = true
radioTypeField.required = false
radioTypeField.formValue = null
}
}
else {
radioTypeField.readOnly = false
}
And also, you wrote this part wrongly: it.status.name != "Done"
This should be "not equal" since if the count of not "Done" issues is important for us. Please review the first code that I shared and this one.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Salih Tuç
I followed the same as you guided with the below code in Initialiser and I also added log debug to see where it is landing in the if-else:
import org.apache.lo4j.Logger
import org.apache.log4j.Level
def radioTypeField = getFieldById("customfield_17500")
def parentIssueTypeName = underlyingIssue.issueType.name
def parentStatusName = underlyingIssue.status.name
def log = Logger.getLogger(getClass())
log.setLevel(Level.DEBUG)
// Using Advanced Roadmap hierarchy such as Portfolio Parent as Initiative and Portfolio Child as Portfolio Epic
if(parentIssueTypeName == "Initiative" && parentStatusName == "Repository"){
// All Portfolio Epic Children are linked with Initiative via Parent Link custom field instead of Subtasks
def childIssues = underlyingIssue.getSubTaskObjects().findAll
{
it -> it.issueType.name == "Portfolio Epic"
&& it.status.name != "Done" }
// Portfolio Epic Children can be one or more and are in Done status already
if(childIssues.size() > 0)
{
log.debug("Entered in Parent-Repository & If C>0")
// Radio Type customfield should be editable and required
radioTypeField.readOnly = false
radioTypeField.required = true
}
else {
log.debug("Entered in Parent-Repository & Else")
// Radio Type custom field should be in ReadOnly, Not required and set to None
radioTypeField.readOnly = true
radioTypeField.required = false
radioTypeField.formValue = null
}
log.debug("Entered in Parent-Repository But Outside of If & Else")
}
else {
log.debug("Entered in Parent-Not Repository")
radioTypeField.readOnly = false
}
But it seems, Radio Type Field is still in ReadOnly mode although Parent is in Repository and Child is in Done statuses.
And the log says:
Entered in Parent-Repository & Else
Entered in Parent-Repository But Outside of If & Else
but it is not entering "If childIssues > 0" condition, when Parent is in Repository & Child is in Done i.e. Entered in Parent-Repository & If C>0
I want to see Radio Type Field as Editable and Required when Parent is in Repository and Child is in Done, apart from this Radio Type Field should be in ReadOnly.
Please guide if I am still missing anything in the code, I am new to groovy coding.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please find related screenshots below:
Parent in Repository
Child in Done with Parent Link
Radio field is ReadyOnly on Parent issue - instead it should be in Editable and Required on Parent issue if Parent is in Repository and Child is in Done
Log debug at this time
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Salih Tuç
I tested getSubTaskObjects() by creating a Sub-task under Initiative and I am able to get in "If (childIssues.size() > 0)" condition successfully.
So, it seems, getSubTaskObjects() is not working with "Parent Link" field between Parent as Initiative and Child as Portfolio Epic as it is only checking if relate Sub-task(s) is present under Initiative.
Please guide if there is any other method to call Child issues linked by Parent Link field, or let me know if it needs any changes in the above code.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I thought that one of them is Task-level and the other one is Sub-task level and they are on same project; so you are correct.
Then I think a simple JQL check will work:
project = ZCP and "Parent Link" = ${underlyingIssue.key} and status != Done
Run this query at the start of the code instead of getSubTaskObjects() and then check its count. If its count is bigger than zero; then you should disable the option; if equals to zero; then we are good to go.
I can share the code with you but I am not on my computer right now; so let's try it yourself and if you face with anything on that logic let me know :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Digvijay Singh Gehlot ,
Do you have any progress?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.