Query for child issues where something in the 'Details' portion of the issue doesn't match parent
Asked by Sofie Palacios:

Exactly like the title mentions... I am trying to query for when a child issue doesn't match certain parts of their parent from the 'Details' section of the issue.

I do have access to scriptrunner and am totally at a loss.

Any help would be very appreciated!


Answers:
author: Ram Kumar Aravindakshan _Adaptavist_
body: Hi [@Sofie Palacios](/t5/user/viewprofilepage/user-id/5366457)

Please clarify, what field type are you using for the Details? Is it a Multi-Line text field?

And what type of comparison are you trying to make between the parent and child field? Is it for a particular word or multiple lines of text?

I am looking forward to your feedback and clarification.

Thank you and Kind regards,

Ram

comments: author: Sofie Palacios
body: Howdy Ram!

It is drop down field. I'm not sure if it comes standard for Jira, but as an example...

What I am trying to see is if the drop down field for the parent is set to 'Cat', I want to see all child issues where their drop down fields don't match their parent (i.e. set to 'Dog' instead).


author: Ram Kumar Aravindakshan _Adaptavist_
body: Hi [@Sofie Palacios](/t5/user/viewprofilepage/user-id/5366457)

So for your requirement, you can easily do a query using the ScriptRunner console.

Below is a sample working code for your reference:-  

```
import com.adaptavist.hapi.jira.issues.Issues

def issue = Issues.getByKey('MOCK-1')
def parentListValue = issue.getCustomFieldValue('Sample List')

def differentOptions = [:]

issue.subTaskObjects.each { subTask ->
    def subTaksListValue = subTask.getCustomFieldValue('Sample List')

    if (subTaksListValue != parentListValue) {
         differentOptions << ["${subTask.key}": "${subTask.getCustomFieldValue('Sample List')}"]
    }
}

differentOptions
```

Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.

Below is a screenshot of the sample output:-

![console.png](https://community.atlassian.com/t5/image/serverpage/image-id/342072iA5A95EF86894CA28/image-size/large?v=v2&px=999 "console.png")

For this use case, I have created a sample Task Issue with a Couple of Sub-Tasks.

Below are the screenshots for your reference:-

1. For the Task Issue the value Option1 has been selected from the Sample List field as shown in the screenshot below:-

![test1.png](https://community.atlassian.com/t5/image/serverpage/image-id/342073iB3901339416945EC/image-size/large?v=v2&px=999 "test1.png")

2. Below are the screenshots of the Sub-Tasks:-

![test2.png](https://community.atlassian.com/t5/image/serverpage/image-id/342074iE1AF4FB2EED55232/image-size/large?v=v2&px=999 "test2.png")

![test3.png](https://community.atlassian.com/t5/image/serverpage/image-id/342075iD5EE75DFD12E1B45/image-size/large?v=v2&px=999 "test3.png")

![test4.png](https://community.atlassian.com/t5/image/serverpage/image-id/342076iAD192AD7071F0A96/image-size/large?v=v2&px=999 "test4.png")![test5.png](https://community.atlassian.com/t5/image/serverpage/image-id/342077iCF1C2C10FB05FCD0/image-size/large?v=v2&px=999 "test5.png")![test6.png](https://community.atlassian.com/t5/image/serverpage/image-id/342078iEB25E0B98E9D6BAA/image-size/large?v=v2&px=999 "test6.png")

In the screenshots above all the Sub-tasks except for Sub-taks MOCK-4 and MOCK-7 have the same value in the single select list as the parent issue.

Hence, only MOCK-4 and MOCK-7 are displayed in the result as expected.

I hope this helps to solve your question. :-)

I am looking forward to your feedback.  

Thank you and Kind regards,  
Ram


author: Ram Kumar Aravindakshan _Adaptavist_
body: Hi [@Sofie Palacios](/t5/user/viewprofilepage/user-id/5366457)

Has your question been answered? If yes, please accept the answer.

Thank you and Kind regards,

Ram


Tags: data-center

jira-data-center

scriptrunner