Forums

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

Call Behavior Script Class function with context and args

Justin Hanselman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 4, 2019

We are currently experimenting with script runner to roll out a rather large customization of JIRA.  The number of behaviors that we are using is getting rather unwieldly and a lot of these scripts are basically carbon copies of each other with a variation on the field name, or another token.

 

The Behavior's loader for scriptrunner describes that I can pick a Run method if the script being pointed to is a class. 

MY ASSUMPTION was that this is meant to work like calling the main method or like the java command line executable.

I tried different syntaxes for calling a method with arguments, but was only able to get it to work with a 0 parameter static void function.  Additionally, the FieldBehaviors base class that a basic script has, is not available to the class whether I inherit Field Behaviors or try a Dependency Injection approach through the main class arguments.  

There are ways to work around this from an organizational standpoint, but I would like to know if this is a feature that is planned to be implemented or if my understanding is grossly off on this.

Thanks for any help!

 

1 answer

0 votes
Tom Lister
Community Champion
January 6, 2019

Hi @Justin Hanselman

I have followed two strategies for similar problems.

where I had a repeating script that only varied by named fields, I wrote the script so all variations were set as constants at the start. This made copy and paste easier but didn’t fix the volume of code.

Ultimately groovy is calling the underlying java classes so you can build a jar file of utility classes and put in the Jira lib directory. I created a library of date manipulation utils to reuse across different scripts.

Erik Grinnell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 7, 2019

[removed]

Justin Hanselman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 8, 2019

Hi @Tom Lister,

    Thanks for the info.  The current solution is to extend base classes with hard-coded values in the extending context for each separate field (much like yours) and use the loaded script functionality.

     I still would like to know if this is the intended behavior of the behavior class method input, or if it is a feature that is not at full maturity yet.

Suggest an answer

Log in or Sign up to answer