ScriptRunner: cannot seem to make this work in JQL
Asked by Mircea Craciun:

Hello, I recently enable script runner and I'm trying to filter for ticket in epics with specific due date. I tried a few JQL like below  

issue in allIssuesInEpic("duedate \<= '2024-07-01'")  

or

parent in issuesInEpics("duedate \<= '2024-07-01'")

but jira complains there is no such function as the ones I named.  
What do I need to do to enable script runner in JQL? And are those the actual functions for what I am trying to do?  

Thank you


Answers:
author: Trudy Claspill
body: Hello [@Mircea Craciun](/t5/user/viewprofilepage/user-id/5503070)

If you have just recently added the app to your instance, you must first execute the Synch function before you can successfully get results from your searches.

<https://docs.adaptavist.com/es/latest/get-started/synchronising-keywords>

Then, to create a filter that uses ScriptRunner functionality you must go to the Enhanced Search screen available from the Apps menu.

![Screenshot 2024-06-07 at 8.45.59?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/328647iB44AE9F406810F7F/image-size/large?v=v2&px=999 "Screenshot 2024-06-07 at 8.45.59?AM.png")

You can't use ScriptRunner functions directly in the View All Issues or other native Jira issue filtering screens.

<https://docs.adaptavist.com/es/latest/run-a-search>

Next, you need to use the correct function and syntax, which you can find in the app documentation.

<https://docs.adaptavist.com/es/latest/run-a-search/jql-functions#issuesinepicssubquery>

issuefunction in issuesInEpics("duedate \<= '2024-07-01'")

comments: author: Mircea Craciun
body: [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)Thank you. I see on the enhanced search window "[JQL Sync Status](https://itxcast.atlassian.net/plugins/servlet/ac/com.onresolve.jira.groovy.groovyrunner/jql-sync?s=com.onresolve.jira.groovy.groovyrunner__jql-sync) FULLY SYNCED" so I assume that is good.  
Running your proposed query there though gets no results, yet we have a lot of epics with due date June 28th 2024 (some in progress, some todo, some done) and all our tickets (bugs, stories, tasks) are assigned to an epic. (also epics with Due Date later than July 1st 2024)

Any idea what could be wrong?  

Thanks.


author: Trudy Claspill
body: Run the keyword synch then try again.

<https://docs.adaptavist.com/es/latest/get-started/synchronising-keywords>


author: Mircea Craciun
body: [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)

still no luck

![Screenshot 2024-06-11 094304.png](https://community.atlassian.com/t5/image/serverpage/image-id/329061iD535E0F1692CD89F/image-size/large?v=v2&px=999 "Screenshot 2024-06-11 094304.png")

Interestingly, if I try and add the same with the helper, it shows a partial result (there should be more) but when I added that to the list, it still results in 0.

![Screenshot 2024-06-11 094655.png](https://community.atlassian.com/t5/image/serverpage/image-id/329062i8CD21FBE38CD053A/image-size/large?v=v2&px=999 "Screenshot 2024-06-11 094655.png")


author: Trudy Claspill
body: I have had some oddities with the Enhanced Search sporadically where I have typed in the JQL directly on the screen but it says the JQL is invalid or gives an odd result. I've never figured out why.

But if I use the helper to create the same JQL, then it works.

When using the helper there is a button at the bottom right corner of the helper pop up to add the content of the helper to the query. Have you used that? The pop-up is too big to display entirely on my screen so I have to scroll down to see that button.

![Screenshot 2024-06-14 at 10.11.30?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/329976iB6FC587B1C80C780/image-size/large?v=v2&px=999 "Screenshot 2024-06-14 at 10.11.30?AM.png")


author: Mircea Craciun
body: Yes, I have used the helper that way. Any idea what that "Team managed projects" notification is that is showing up? Clicking on more info just gets me to the blogs, and I don't know how to see if I'm hitting that "wall" or not.  
Thanks


author: Trudy Claspill
body: In Jira Cloud there are two over-arching project types - Company Managed and Team Managed. You can find out which type your project is by going to the View All Projects page under the Projects menu, finding your project in the list and looking at the Type column.

The query within the helper dialog gives you the same results as if you ran the identical query (duedate \< '2024-07-10') in the regular issue search screen. It is not yet applying any other criteria to it related to the function that you want to use. You can click on the link to see the actual issues it has found based on that portion of the query.

![Screenshot 2024-06-19 at 9.28.46?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/330678iB7F8E1DF6C912F55/image-size/large?v=v2&px=999 "Screenshot 2024-06-19 at 9.28.46?AM.png")

Those results will include all issues of all types in all projects (to which you have access) that match the subquery.

When you then insert that subquery into the function, that applies another layer of criteria. In the case of the issuesInEpics function, you are getting the Epics that match the subquery first, and then getting all the child issues in those Epics as the final results.

However, if any of those Epics are in Team Managed projects, they and their child issues will be excluded.

If you think you have an Epic that matches the subquery, that has child issues that should be in the results set, and that Epic (and the child issues) are not in a Team Managed project, can you share screen images of that Epic showing the due date and the child issues?


author: L?gia Zanchet
body: hi Mirceao  

I don't know if you follow this instruction here on how to add the functions to the JQL search:   

<https://docs.adaptavist.com/sr4js/latest/features/jql-functions>  

Thanks

comments: author: Mircea Craciun
body: Yes, I have. But the documentation there is misleading/incorrect. If you read the page it clearly says "You can use ScriptRunner JQL functions anywhere you are able to use Jira JQL functions" So I go to issue search, where I can use Jira JQL, copy the code form their example on that very page that reads

* Use issuesInEpic to find all stories for open epics in a project, and then look specifically at the status of issues, such as 'in progress.'

And I get  
![Screenshot 2024-06-19 122712.png](https://community.atlassian.com/t5/image/serverpage/image-id/330550i341EB40F738137C7/image-size/large?v=v2&px=999 "Screenshot 2024-06-19 122712.png")

If I go to \`ScriptRunner Enhanced Search\` as suggested by Trudy above, you can see my problem, with the helper showing 31 results but actually running it returning 0.


Tags: cloud

jira-cloud

scriptrunner