Hi, I need to obtain values of special custom-field from all linked issues (one custom-field = one linked issue) to the parent issue. Unfortunatetly when I run it my jira is looping and I'm forced to restart it.
What are you trying to do ? What does "(one custom-field = one linked issue) to the parent issue" means ?
Regards
it means that each linked issue have a single value of custom field 'customfield_24201'.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What type of field is it and what do you want to do with the values from the sub elements ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, field is float and main goal is to sum values of all 'customfield_24201' in linked issues.
Unfortunately maybe code is not right to sum all fields but I was stopped in step to get properly the values so I haven't think about the next steps (to summarize them).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This should work
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.event.type.EventDispatchOption
log.warn("PARENT JIRA ISSUE: " + issue)
def currentUser2 = ComponentAccessor.jiraAuthenticationContext.loggedInUserdef linkedIssues = ComponentAccessor.issueLinkManager.getLinkCollection(issue, currentUser2).getAllIssues()
def cField = ComponentAccessor.customFieldManager.getCustomFieldObject('customfield_24201')def issueManager = ComponentAccessor.getIssueManager()double cFieldValue = 0.0log.warn("PARENT ISSUE VALUE: " + cFieldValue)MutableIssue issueUpdated = issue as MutableIssuelinkedIssues.each{ issueLinked ->log.warn("LINKED JIRA ISSUE: " + issueLinked.key)log.warn("LINKED JIRA ISSUE PROJECT: " + issueLinked.projectId)if (issueLinked.projectId == 34343) {cFieldValue += issueLinked.getCustomFieldValue(cField) ? issueLinked.getCustomFieldValue(cField) as double : 0.0}}issueUpdated.setCustomFieldValue(cField, cFieldValue)issueManager.updateIssue(currentUser2, issueUpdated, EventDispatchOption.ISSUE_UPDATED, false)
//log.warn(linkedIssues)if (cFieldValue == 0) {return null}else {return cFieldValue}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Florian Bonniec may I asked you for one thing. Code is working fine when it is being triggered during view pf an issue in browser. However if I list all issues in a project in Issue Navigator and add column with value of that field I'm receiving errors and column is empty. Problem is with the loop which gather values of field from linked issues:
44.79,10.200.31.198 /rest/issueNav/1/issueTable [c.o.scriptrunner.customfield.GroovyCustomField] Script field failed on issue: BIIC-893, field: Total time consumption
java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:878)
at org.codehaus.groovy.runtime.ProxyGeneratorAdapter$InnerLoader.defineClass(ProxyGeneratorAdapter.java:846)
at org.codehaus.groovy.runtime.ProxyGeneratorAdapter.<init>(ProxyGeneratorAdapter.java:194)
at groovy.util.ProxyGenerator.lambda$createAdapter$0(ProxyGenerator.java:234)
at org.apache.groovy.util.concurrent.concurrentlinkedhashmap.ConcurrentLinkedHashMap.lambda$compute$0(ConcurrentLinkedHashMap.java:788)
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
at org.apache.groovy.util.concurrent.concurrentlinkedhashmap.ConcurrentLinkedHashMap.compute(ConcurrentLinkedHashMap.java:800)
at org.apache.groovy.util.concurrent.concurrentlinkedhashmap.ConcurrentLinkedHashMap.computeIfAbsent(ConcurrentLinkedHashMap.java:777)
at org.codehaus.groovy.runtime.memoize.LRUCache.getAndPut(LRUCache.java:63)
at groovy.util.ProxyGenerator.createAdapter(ProxyGenerator.java:230)
at groovy.util.ProxyGenerator.instantiateDelegateWithBaseClass(ProxyGenerator.java:205)
at groovy.util.ProxyGenerator.instantiateDelegateWithBaseClass(ProxyGenerator.java:189)
at groovy.util.ProxyGenerator.instantiateDelegate(ProxyGenerator.java:181)
at groovy.util.ProxyGenerator.instantiateDelegate(ProxyGenerator.java:177)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.asType(DefaultGroovyMethods.java:17939)
at org.codehaus.groovy.runtime.dgm$56.doMethodInvoke(Unknown Source)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1268)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1035)
at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:1017)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:1008)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:180)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asType(ScriptBytecodeAdapter.java:603)
at Script2.run(Script2.groovy:16)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155)
at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
at javax.script.ScriptEngine$eval.call(Unknown Source)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:185)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$2.callCurrent(Unknown Source)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:304)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$1.callCurrent(Unknown Source)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScript(AbstractScriptRunner.groovy:316)
at com.onresolve.scriptrunner.runner.ScriptRunner$runScript$10.call(Unknown Source)
at com.onresolve.scriptrunner.customfield.GroovyCustomField$_getValueFromIssue_closure4.doCall(GroovyCustomField.groovy:278)
at com.onresolve.scriptrunner.customfield.GroovyCustomField$_getValueFromIssue_closure4.doCall(GroovyCustomField.groovy)
at jdk.internal.reflect.GeneratedMethodAccessor1109.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:274)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1035)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:38)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl$_execute_closure1.doCall(DiagnosticsManagerImpl.groovy:397)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have implemented it as a script field ?
If so I think you have to go in each issue so it will set the value.
I usually avoid this kind of field so I'm not 100% aware of how they work.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The HAPI feature introduced in ScriptRunner 7.11.0 should make this straightforward
Here is some sample code to sum the value of a "Counter" custom field on all linked issues:
issue.inwardLinks*.sourceObject.collect { linkedIssue ->
linkedIssue.getCustomFieldValue('Counter')
}.sum()
Cheers :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Reece Lander _ScriptRunner - The Adaptavist Group_ ,
I'm trying to use your script to retrieve value from a linked issue customer field. However, It's not returning any value. Please see the attached screenshot.
Thanks
Roshan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.