Groovy Script Runner: Custom Parameters for Custom Scripts

Ruben Straube August 31, 2014

Hello,

I've created a script to send an E-Mail to watchers of the parent issue upon creation of a subtask. The script is based very much on the built-in SendCustomEmail.groovy; in fact, it is only an additional seven lines. (Why re-write functionality if you can use existing one.)

Unfortunately, the SendCustomEmail.groovy uses additional parameter fields that I cannot use. Is there a way to use custom parameters for custom scripts? Alternatively, if Jamie Echlin reads this: Do we have a chance of this functionality being built-in? I will happily send you those seven lines to add :-)

Kind regards

Ruben Straube

1 answer

0 votes
JamieA
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.
September 1, 2014

If you have subclasses the script or just copy and paste it you should see the parameters when you add it to a workflow. So I don't really get your question, if you could use the original why can you not use your copy?

> Do we have a chance of this functionality being built-in? I will happily send you those seven lines to add

Depends what the 7 lines are! What do they do?

MartinS
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.
September 1, 2014

> you should see the parameters when you add it to a workflow.

It is not added to a workflow, it is a "Script Listener" that should listen to the "issue created" event (If the created issue is a sub task, the watchers of the parent issue should be notified).

So we go to "Script Listeners" in the admin area, and no matter where we put our Listener, only the built-in ones are displayed. Choosing "Custom listener" does not give us the parameters we defined (obviously).

JamieA
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.
September 1, 2014

Well, what version of Script Runner are you using, and where are you putting it?

It needs to have the @ScriptListener annotation for listeners.

Ruben Straube September 1, 2014

To add to what Martin wrote:

Those lines are to use the parent issue's watcher field; it's a functionality we've been asked about a lot recently. I only added

else if (f == "parentwatchers") {
                    if(issue.isSubtask()) {
                        watcherManager.getCurrentWatcherUsernames(issue.getParentObject().genericValue).each { String username ->
                            addresses.add(userUtil.getUser(username).emailAddress)
                        }
                    }
                }

into the long if .. else if clause in the function getAddressesFromFields(...).

JamieA
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.
September 1, 2014

OK that's related to that other discussion? Can we keep that separate.

Again: Well, what version of Script Runner are you using, and where are you putting it?

Ruben Straube September 1, 2014

The full script is this one here: https://www.refheap.com/89702

Since the code is essentially the same as the SendCustomEmail.groovy with some additional lines and another class name, the annotation @ScriptListener is there.

The script runner version is 3.0.3. It doesn't matter if I put it into the scripts folder or paste it; the class is found, but I still get the same parameters as any custom script and not the same as for the custom email listener.

JamieA
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.
September 1, 2014

I'll try to repro later.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events