Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Write a groovy ( with script runner ) condition with a JQL filter

wajih zouaoui
Contributor
November 11, 2019

Hi,

 

i need to use Script Runner listners to send a custom Email based on Date Picker custom field value: 

project = "Project" AND "Date Picker Custom Field" = 2d

The Email will be sent if the custom value =< 48h and i need to create a groovy condition on the listner with this jql filter.

Is it possible ?

 

Thanks in advance.

 

Best Regards,

Wajih

1 answer

0 votes
Leo
Community Champion
November 11, 2019

Hi @wajih zouaoui ,

ScriptRunner's listener will run for some events not periodically. if you want to check the JQL condition and if there is any tickets send mail. if that is scenario I would suggest you to consider Filter Subscription feature

 

But yeah, You can use the same JQL query in scriptrunner's listener which you are using in jira filters

with help of searchService. I'm attaching sample snippet for your reference

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
import org.apache.log4j.Logger

def jqlSearch = "\"Epic Link\" = ${issue.key}" // here issue.key refers event's issue
SearchService.ParseResult parseResult = searchService.parseQuery(appUser, jqlSearch)
if (parseResult.isValid()) {
def searchResult = searchService.search(appUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
issues.each { i ->
// your action here
}
}

 

BR,

Leo

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events