Call method from groovy script in condition of a workflow function

Hey!

As I am trying to be a good developer, I am putting all my groovy code in custom scripts in the scripts-folder and call the method I need from ScriptRunner.

Example:

Inside my scripts/ - folder is a file test.groovy with following content:

class CheckUtil {
public static boolean check(field) {
/* some 50 lines, complex, multiple times needed method */
/* ... */
return field.value == "42" // for simplicity
}
}

Then, I want to use the "Set security level"-post function in my workflow, to set specific security levels based on custom fields. Therefore, I must specify some conditions like "if customfieldvalue is 42, then set security level to 42" or something.

As my conditions are inside the test.groovy and I do not want spreaded/duplicated code, I simply want to call:

CheckUtil.check(
customFieldManager.getCustomFieldObject('customfield_10000')
)

No errors were found, the compiler-indicator is green. But sadly, when the condition is executed, I get:

Condition failed on issue: TEST-27, built-in script:com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SetIssueSecurity
groovy.lang.MissingPropertyException: No such property: CheckUtil for class: Script165
at Script165.run(Script165.groovy:1)

So, my questions are:

  • How can I call methods from my scripts inside the scripts/-folder?
  • Why is the compiler-indicator green?

Thanks a lot for any help!

 

1 answer

0 votes

It sounds like you are running into an open bug detailed here: https://productsupport.adaptavist.com/browse/SRJIRA-458

Unfortunately, you can not import classes from your script roots into the inline editor, due to the way we handle class loading for the two cases. Although the static type checker will say it compiles fine, it isn't run in the same way. You won't be able to access class methods from your script roots in the inline editor until the bug is fixed.

You might try the workaround on that bug report, though it can be a challenge to get it work in my experience. Short of that, you'll have to run the script from a script file if you want to access your class methods. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

357 views 0 1
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you