Filter Id as Parameter to Groovy Service

Krishnanand Nayak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 17, 2019

I am trying to setup a service to send out emails based on a JQL. Followed the instructions mentioned here: https://scriptrunner.adaptavist.com/latest/jira/services.html

Now we need to make this generic so that it can be set up to run for multiple different filters. Currently the groovy file that has an hard coded JQL. 

So the question is:

1) How do i pass the filter id to the groovy file when setting up the service? 

2) What should the script look like after the Point 1 above is answered? Here is how my current code looks like:

//Get the SearchRequestManager
def searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager) //Find the filter using the SearchRequestManager
def filter = searchRequestManager.getSearchRequestById(10001)

//Get the jql query
def jqlQuery = filter.query

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 26, 2019

You can't pass a parameter to a groovy script from any of the scriptrunner interfaces.

One thing you could do is transform your script into a class with a method that accepts a JQL or filterId. Then for each instance of the service, you want to create you have a separate script that imports your class above and calls the method with the desired argument.

 

Something like this:

YourEmailService.groovy

public class YourEmailService{
void sendMailForFilter(filterId){
def searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager)
def filter = searchRequestManager.getSearchRequestById(filterId)
//etc
}
}

 EmailserviceFilter10001.groovy

import YourEmailService

YourEmailService.sendMailForFilter(10001)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events