Community Announcements have moved! To stay up to date, please join the new Community Announcements group today. Learn more
×Hi,
I've tried to load a file containing a common class through
def utils = new GroovyScriptEngine( '/var/atlassian/application-data/jira/scripts/com/mprv/automations/EscalationSLA' ).with { loadScriptByName( 'EscalationSLA_utils.groovy' ) }
this.metaClass.mixin utils
Now, this sub-script contains calls to ruleContext:
String smartValue(value) { return ruleContext.renderSmartValues(value) }
(yes, I'm lazy - don't judge...)
however getting the error
com/mprv/automations/EscalationSLA/EscalationSLA_IssueTransition.groovy, error: groovy.lang.MissingPropertyException: No such property: ruleContext for class: EscalationSLA_IssueTransition groovy.lang.MissingPropertyException: No such property: ruleContext for class: EscalationSLA_IssueTransition at Utils.smartValue(EscalationSLA_utils.groovy:18) at EscalationSLA_IssueTransition.run(EscalationSLA_IssueTransition.groovy:50)
Seemingly, the rule context is not passed to the runtime of the second file - is this even possible?
3 years later, I've found a solution to use the utils class within or without an automation rule -
class SlaUtils {
private MutableIssue issue
private Logger log
private Object ruleContext
SlaUtils (MutableIssue issue, Logger log, ruleContext=null) {
this.issue = issue
this.log = log
this.ruleContext = ruleContext
}
then I can either call it either with:
SlaUtils slaUtils = new SlaUtils(issue, log)
in case I am calling from console without a rule context, or with:
SlaUtils slaUtils = new SlaUtils(issue, log, ruleContext)
from actual automation rule.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.