Forums

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

Need Grrovy script urgent please

sai chinamuthevi
Contributor
March 7, 2023

Hi Team,

I have one urgent requirement,

we have two fields called Impacting and Probability.

and we have one more field called rating. all these are number fields.

requirement is when ever issue is created for issue type task we have to populate values of Impacting and Probability and rating should populate automatically as Impacting * Probability.

I created script filed with the Below script

def number1 = getCustomFieldValue("Impacting")
// You can pass in Custom Field ID too!

def number2 = getCustomFieldValue("Probability")

// If the field is empty, set the value as 0

if (!number1){

number1 = 0

}
if (!number2) {

number2 = 0

}

return number1 * number2 .

This is working fine for another user but for me it's showing error like 

 

org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: Script1.getCustomFieldValue() is applicable for argument types: (String) values: [Impacting] at TestScriptedFieldExecution1_groovyProxy.run(Unknown Source) Caused by: groovy.lang.MissingMethodException: No signature of method: Script1.getCustomFieldValue() is applicable for argument types: (String) values: [Impacting] at Script1.run(Script1.groovy:1) at Script1$run.call(Unknown Source) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:33) at com.adaptavist.sr.cloud.events.ScriptedFieldExecution.run(ScriptedFieldExecution.groovy:30) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at TestScriptedFieldExecution1_groovyProxy.run(Unknown Source) at com.adaptavist.sr.cloud.MainHandler.executeScript(MainHandler.groovy:409) at com.adaptavist.sr.cloud.MainHandler.processInput(MainHandler.groovy:355) at com.adaptavist.sr.cloud.MainHandler.access$0(MainHandler.groovy) at com.adaptavist.sr.cloud.MainHandler$_handleRequest_closure1.doCall(MainHandler.groovy:171) at com.adaptavist.sr.cloud.MainHandler$_handleRequest_closure1.call(MainHandler.groovy)

Can some one please explain how can i achieve this trough script runner ?

1 answer

0 votes
Aron Gombas _Midori_
Community Champion
March 7, 2023

The error means that this method:

getCustomFieldValue()

doesn't exist.

I'd think that you were not copying the complete script (because this fragment doesn't declare that method so the error is expected) or your team mate who got this working uses some external script/library to provide that method.

Nic Brough -Adaptavist-
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.
March 9, 2023

Indeed, "getcustomfield" needs the issue context.

If this code is in a post-function, it will have that context, but it still needs to go back to the issue.  The starting point would probably be

def number1 = issue.getCustomFieldValue("Impacting")

(But that does assume a whole load more stuff that you might need to check for - field exists on issue, there's only one field and and and)

Suggest an answer

Log in or Sign up to answer