It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to use the project event filter in scriptrunner script ?

Hello,

I am using a script listener triggered by the issue_commented event in order to recopy comments to a linked issue.

I would like to restrict the use to some projects though and I noticed that the project filter of the event is only applying for the issue concerned by the event.

So now my idea would be to get the list of values entered in the project filter and use it in the script to check if the linked issue is in the project listed.

But I cannot find how to recover this list of values in the script. Could somebody help me with that ?

 

Thank you very much in advance.

1 answer

hello, looks like this one will give you list of listeners:

import com.onresolve.scriptrunner.runner.util.OSPropertyPersister
import com.onresolve.scriptrunner.runner.ListenerManagerImpl
import com.onresolve.scriptrunner.runner.ListenerManager
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def listenerManager = ScriptRunnerImpl.getPluginComponent(ListenerManager)

OSPropertyPersister.loadList(ListenerManagerImpl.CONFIG_LISTENERS)

where you can find them by id and get list of project keys

Thank you very much for your quick answer, could you please precise to me how I will get the list of project keys ?

OSPropertyPersister.projects ?

like this:

def listenerList = OSPropertyPersister.loadList(ListenerManagerImpl.CONFIG_LISTENERS)
def projects = listenerList.find {
it.id == "fb47asb6-7619-42a9-8ef3-a9ce66e2d842"
}.projects

where you can find id in a listener page edit url:

$baseUrl/plugins/servlet/scriptrunner/admin/listeners/edit/fb47asb6-7619-42a9-8ef3-a9ce66e2d842

if listener is for all projects, the list it returns will be empty

Oh I really wouldn't have found it myself.

I still get error message in edit mode for the line below as well as for another line where I iterate, but strangely it does work.

def projects = listenerList.find {
it.id == "fb47asb6-7619-42a9-8ef3-a9ce66e2d842"
}.projects

Yeah, groovy does some static typechecking and because we are not defining stuff statically, but dynamically here, it's not sure methods we are calling are legit.

Something along those lines.

I get it. Thank you very much though.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

966 views 9 25
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you