Reference a Scripted Field in another Scripted Field

Andrew Frayling
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.
April 7, 2014

Hi.

Is it possible to reference an existing script field in another script field with the Script Runner plugin (v2.1.15)?

I've got a scripted field that calculates the response time in hours for an issue and now need another field to set a "Breached SLA" flag on the ticket. Ideally I'd like to be able to reference the Response Time in the new field so I can just say Response Time > 4, for example, rather than having to duplicate the Response Time logic in the second scripted field, but the following just produces "Server Error" when trying to preview the field on the Sctiped Field screen and nothing in the logs:

def responseTime = getCustomFieldValue("Time to Respond");

if (responseTime > 4) {
  return "Yes";
} else {
  return "No";
}

Am I doing something wrong, or do I have to duplicate the logic because you can't reference a Scripted Field from another Scripted Field?

Cheers,

Andrew.

2 answers

1 accepted

2 votes
Answer accepted
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 7, 2014

Hello Andrew,

you need to replicate your "Time to Respond" code into the second scripted field. You can't use an existing scripted field.

Hope this helps,

Fabio

Andrew Frayling
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.
April 9, 2014

Thanks Fabio.

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.
April 7, 2014

You can do that... can you post the stack trace?

Andrew Frayling
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.
April 7, 2014

Hi Jamie,

Checking again it's given me a stack overflow:

java.lang.StackOverflowError
        at groovy.lang.MetaClassImpl.getMethods(MetaClassImpl.java:614)
        at groovy.lang.MetaClassImpl.getMethodWithoutCaching(MetaClassImpl.java:1260)
        at groovy.lang.MetaClassImpl.pickMethod(MetaClassImpl.java:3316)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:269)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
        at com.onresolve.jira.groovy.ScriptManagerImpl$_getAsActualType_closure9.doCall(ScriptManagerImpl.groovy:299)  <+2>
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)
        at groovy.lang.Closure.call(Closure.java:412)
        at groovy.lang.Closure.call(Closure.java:425)
        at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1377)
        at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1349)
        at org.codehaus.groovy.runtime.dgm$149.invoke(Unknown Source)

"Time to Respond" is my existing Scripted Field and I'm previewing it against an issue that has a value of 405 for tha field. I'm previewing in the Script Fields view rather than the Console.

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.
April 8, 2014

Sorry, my mistake, it is a bug and Fabio is correct. I have fixed it for the next release, please watch https://jamieechlin.atlassian.net/browse/GRV-431to get notified about when the release happens...

Andrew Frayling
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.
April 9, 2014

Cheers Jamie.

Suggest an answer

Log in or Sign up to answer