Adaptavist ScriptRunner for JIRA - Groovy Scripts stop working after update

hello

since the update of the script runner plugin our groovy scripts which just place a comment in the ticket does not work anymore.

4.1.3.11

6 answers

1 vote

You are giving the commentMgr.create call parameters it is not written for.  The issue, currentUser and boolean look right to me, but the error message saying "try grep or iterator" suggest that sourceFieldVal is some form of array, and your code on line 13 seems to be using it as such.

 

I absolutely do not understand anything you are telling me :->

Ok, but you need to understand this stuff if you're going to be writing scripts.  I'd suggest an introduction to java or groovy course if you can find one.

Going back to the code, look at the last screenshot.  Look at line 25 - it makes a call with four parameters.  The error box is saying "I expected you to pass me an issue, a user, some text and a true/false flag, but you've passed me something else and I'm not written to handle" ("Overloading" is the word you'll see if you do a java course)

The error then goes on to try to suggest a fix - your IDE is looking at what you've passed in, and trying to suggest how to convert it to what the code needs.  In this case, you've passed it a valid issue, a valid user, and a valid flag, but where it wanted a string, you've got something else.  Because your IDE is suggesting the use of grep or an iterator, that suggests that you are passing it an array or list of some sort.

So, either go over that list to find the entry you want as a string, OR, go back to lines 12/13 where you appear to be creating an array instead of a string, and correct them so that they generate a string.

0 vote

At a glance, the sourceFieldVal variables should have "def" in front of them

ok that is gone i am not a expert in groovy there still errors

defset.png

Where do you try to execute this script?

In a transition? In a listener? What's your context?

I think you try to execute this code in the "Script console". But there is no object "issue". On which issue, you want to add the comment? On all issues? On an issue? On an issue using one transition in a workflow?

For one issue paste this to line 10:

def issue = ComponentManager.getIssueManager().getIssueObject("ISSUE-123");

 

So issue is defined and you will add your comment to ISSUE-123.

If you will add the comment on an issue using one transition, you will have to add the code in a post function. And there "issue" will be predefined.

hello robin

the script will be executed when you use a transition.it will paste a comment as the current user.

i use the script console to check the the syntax.

the script works since the update of the plugin

Then the syntax should be okay with the "def" in front of sourceFieldVal.

this is the error on catalin.out when a execute the transition where the script should be executed

2016-05-04 08:44:13,144 http-bio-9001-exec-16 ERROR ad 524x8689x1 xh1b52 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TS-7732, actionId: 21, file: /data/home/jira/groovyscripts/TS-HardwareSale-AbverkaufFreigeben.groovy

java.lang.NullPointerException: Cannot get property 'displayName' on null object

        at TS-HardwareSale-AbverkaufFreigeben.run(TS-HardwareSale-AbverkaufFreigeben.groovy:12)

 

 

Try:
def sourceFieldVal = ComponentManager.getCustomFieldManager().getCustomFieldObject("customfield_10900").getValue(issue);

now this error occurs:

2016-05-04 09:27:31,941 http-bio-9001-exec-8 ERROR ad 567x8759x1 xh1b52 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TS-7734, actionId: 21, file: /data/home/jira/groovyscripts/TS-HardwareSale-AbverkaufFreigeben.groovy

groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.ComponentManager.getCustomFieldManager() is applicable for argument types: () values: []

Possible solutions: getCustomFieldManager()

        at TS-HardwareSale-AbverkaufFreigeben.run(TS-HardwareSale-AbverkaufFreigeben.groovy:13)

 

 

Sorry.

compManager.getCustomFieldManager().getCustomFieldObject("customfield_10900").getValue(issue);

you do not have to apologize.

2016-05-04 09:34:28,315 http-bio-9001-exec-10 ERROR ad 574x8865x1 xh1b52 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************

2016-05-04 09:34:28,316 http-bio-9001-exec-10 ERROR ad 574x8865x1 xh1b52 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TS-7737, actionId: 21, file: /data/home/jira/groovyscripts/TS-HardwareSale-AbverkaufFreigeben.groovy

java.lang.NullPointerException: Cannot invoke method getAt() on null object

        at TS-HardwareSale-AbverkaufFreigeben.run(TS-HardwareSale-AbverkaufFreigeben.groovy:15)

 

 

Can you add this print after Line 12?

System.out.println("DEBUG Scriptrunner " + sourceFieldVal)

Is there a value in customfield_10900?

You will find the output in /{jira-application-dir}/logs/catalina.out

Or you can try the code in Script Console with

def issue = ComponentManager.getIssueManager().getIssueObject("TS-7734")

in line 10.

that field is a userpicker.

i added System.out.println("DEBUG Scriptrunner " + sourceFieldVal)

2016-05-04 10:55:07,684 http-bio-9001-exec-16 ERROR ad 655x8962x1 xh1b52 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TS-7739, actionId: 21, file: /data/home/jira/groovyscripts/TS-HardwareSale-AbverkaufFreigeben.groovy

groovy.lang.MissingPropertyException: No such property: sourceFieldVal for class: TS-HardwareSale-AbverkaufFreigeben

        at TS-HardwareSale-AbverkaufFreigeben.run(TS-HardwareSale-AbverkaufFreigeben.groovy:10)

 

 

2016-05-04 10:58:45,376 http-bio-9001-exec-19 ERROR ad 658x8996x3 xh1b52 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************
2016-05-04 10:58:45,376 http-bio-9001-exec-19 ERROR ad 658x8996x3 xh1b52 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TS-7740, actionId: 21, file: /data/home/jira/groovyscripts/TS-HardwareSale-AbverkaufFreigeben.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/data/home/jira/groovyscripts/TS-HardwareSale-AbverkaufFreigeben.groovy: 17: expecting EOF, found 'DEBUG' @ line 17, column 21.
   System.out.println("DEBUG Scriptrunner " + sourceFieldVal)
                       ^

1 error

Nonono. The System.out please after line 12. You use the sourceFieldVal there. And it's just defined in Line 12.

Can you paste your whole code here in a code macro?
So I can change and you just have to paste in Script Console.

2016-05-04 11:05:36,921 http-bio-9001-exec-20 ERROR ad 665x9035x1 xh1b52 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************

2016-05-04 11:05:36,922 http-bio-9001-exec-20 ERROR ad 665x9035x1 xh1b52 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on

groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.ComponentManager.getCustomFieldManager() is applicable for argument types: () values: []

Possible solutions: getCustomFieldManager()

        at TS-HardwareSale-AbverkaufFreigeben.run(TS-HardwareSale-AbverkaufFreigeben.groovy:12)

 

 

  

1 import com.atlassian.jira.ComponentManager

      2 import com.atlassian.jira.issue.comments.CommentManager

      3 import com.atlassian.jira.issue.CustomFieldManager

      4 import com.atlassian.jira.component.ComponentAccessor;

      5 import com.atlassian.jira.user.*;

      6

      7 ComponentManager compManager = ComponentManager.getInstance()

      8 ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser();

      9 CustomFieldManager customFieldManager = compManager.getCustomFieldManager()

     10

     11 //Zusammenbau vom String für den Kommentar

     12 def sourceFieldVal = ComponentManager.getCustomFieldManager().getCustomFieldObject("customfield_10900").getValue(issue);

     13 System.out.println("DEBUG Scriptrunner " + sourceFieldVal)

     14 sourceFieldVal = sourceFieldVal[1..-2]

     15

     16 sourceFieldVal = "Hallo *" + sourceFieldVal + "* \

     17 \n\ndie Hardware steht für dich zum Abverkauf bereit.\

     18 \n\nBitte gib uns in diesem Ticket durch *Kauf bestätigen* Bescheid, ob du die Hardware kaufen möchtest.\

     19 \nAlle relevanten Informationen zur Hardware kannst du oben im Ticket einsehen und sind ebenfalls im Kaufvertrag enthalten.\

     20 \nDer Kaufbetrag wird vom Gehalt abgezogen.\

     21 \n\nNach deiner Bestätigung, wird HR-Confidential den Kaufvertrag im Ticket hinterlegen. Bitte diesen Kaufvertrag ausdrucken, unterschreiben\

     22 \nund bei Technical Services vorbeibringen.\

     23 \nAlternativ kannst du den unterschriebenen Kaufvertrag einscannen und im Ticket hinterlegen.\

     24 \n\nGrü▒~_e\

     25 \nTechnical Services"

     26

     27 CommentManager commentMgr = compManager.getCommentManager()

     28 commentMgr = (CommentManager) compManager.getComponentInstanceOfType(CommentManager.class)

     29 //Der wirkliche Kommentar

     30 commentMgr.create(issue, currentUser, sourceFieldVal, true)

 

 

 

0 vote

Read https://scriptrunner.adaptavist.com/latest/jira/releases/UpgradingToJira7.html and https://scriptrunner.adaptavist.com/latest/jira/#_providing_type_information

Also as people say, the context where you are running stuff defines what is available, eg whether issue is there or not.

import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.*;

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

//Zusammenbau vom String für den Kommentar
Collection userCollection = (Collection) ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10260").getValue(issue);
ApplicationUser[] userarray = (ApplicationUser[]) userCollection.toArray()
String sourceFieldVal = userarray[0].getDisplayName()

sourceFieldVal = "Hallo *" + sourceFieldVal + "* \
\n\ndie Hardware steht für dich zum Abverkauf bereit.\
\n\nBitte gib uns in diesem Ticket durch *Kauf bestätigen* Bescheid, ob du die Hardware kaufen möchtest.\
\nAlle relevanten Informationen zur Hardware kannst du oben im Ticket einsehen und sind ebenfalls im Kaufvertrag enthalten.\
\nDer Kaufbetrag wird vom Gehalt abgezogen.\
\n\nNach deiner Bestätigung, wird HR-Confidential den Kaufvertrag im Ticket hinterlegen. Bitte diesen Kaufvertrag ausdrucken, unterschreiben\
\nund bei Technical Services vorbeibringen.\
\nAlternativ kannst du den unterschriebenen Kaufvertrag einscannen und im Ticket hinterlegen.\
\n\nGrüße\
\nTechnical Services"

CommentManager commentMgr = ComponentAccessor.getCommentManager()
//Der wirkliche Kommentar
commentMgr.create(issue, currentUser, sourceFieldVal, true)

This works for me. I get this comment in my issue:

Hallo Admin User

die Hardware steht für dich zum Abverkauf bereit.

Bitte gib uns in diesem Ticket durch Kauf bestätigen Bescheid, ob du die Hardware kaufen möchtest.
Alle relevanten Informationen zur Hardware kannst du oben im Ticket einsehen und sind ebenfalls im Kaufvertrag enthalten.
Der Kaufbetrag wird vom Gehalt abgezogen.

Nach deiner Bestätigung, wird HR-Confidential den Kaufvertrag im Ticket hinterlegen. Bitte diesen Kaufvertrag ausdrucken, unterschreiben
und bei Technical Services vorbeibringen.
Alternativ kannst du den unterschriebenen Kaufvertrag einscannen und im Ticket hinterlegen.

Grüße
Technical Services

 

 

2016-05-04 11:28:49,293 http-bio-9001-exec-23 ERROR ad 688x164x1 d5peq8 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************

2016-05-04 11:28:49,305 http-bio-9001-exec-23 ERROR ad 688x164x1 d5peq8 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TS-7742, actionId: 21, file: /data/home/jira/groovyscripts/TS-HardwareSale-AbverkaufFreigeben.groovy

groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.getDisplayName() is applicable for argument types: () values: []

        at TS-HardwareSale-AbverkaufFreigeben.run(TS-HardwareSale-AbverkaufFreigeben.groovy:11)

 

 i take the same script and even restarted jira.

which version do you have installed?

 

i use the version 3.0.16

Ok, customfield_10900 is an user field (multi user)?

With a single user this works:

def sourceFieldVal = compManager.getCustomFieldManager().getCustomFieldObject("customfield_10900").getValue(issue).getDisplayName();

 

With multi user:

def sourceFieldVal = compManager.getCustomFieldManager().getCustomFieldObject("customfield_10900")[0].getValue(issue).getDisplayName();

 

I thought you use version 4.1.3.11?

your right version 4.1.3.11 i am confused sorry :->

 

ok your are right that is a multi user picker but it does not work

2016-05-04 11:42:57,901 http-bio-9001-exec-4 ERROR ad 702x259x1 d5peq8 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************

2016-05-04 11:42:57,902 http-bio-9001-exec-4 ERROR ad 702x259x1 d5peq8 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TS-7744, actionId: 21, file: /data/home/jira/groovyscripts/TS-HardwareSale-AbverkaufFreigeben.groovy

groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.fields.CustomFieldImpl.getAt() is applicable for argument types: (java.lang.Integer) values: [0]

Possible solutions: getAt(java.lang.String), getId(), getName(), putAt(java.lang.String, java.lang.Object), wait(), grep()

        at TS-HardwareSale-AbverkaufFreigeben.run(TS-HardwareSale-AbverkaufFreigeben.groovy:13)

 

 do oyu think i need a restart every time a change the script?

nope

2016-05-04 11:47:35,158 http-bio-9001-exec-8 ERROR ad 707x440x1 alxor 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************

2016-05-04 11:47:35,159 http-bio-9001-exec-8 ERROR ad 707x440x1 alxor 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TS-7745, actionId: 21, file: /data/home/jira/groovyscripts/TS-HardwareSale-AbverkaufFreigeben.groovy

groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.fields.CustomFieldImpl.getAt() is applicable for argument types: (java.lang.Integer) values: [0]

Possible solutions: getAt(java.lang.String), getId(), getName(), putAt(java.lang.String, java.lang.Object), wait(), grep()

        at TS-HardwareSale-AbverkaufFreigeben.run(TS-HardwareSale-AbverkaufFreigeben.groovy:13)

 

 

I updated code in my post above.

Please try with componentaccessor and new api.

 

2016-05-04 12:20:33,896 http-bio-9001-exec-1 ERROR ad 740x557x1 116bn5x 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************

2016-05-04 12:20:33,896 http-bio-9001-exec-1 ERROR ad 740x557x1 116bn5x 172.16.177.197,10.0.0.63 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TS-7746, actionId: 21, file: /data/home/jira/groovyscripts/TS-HardwareSale-AbverkaufFreigeben.groovy

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'ad:1' with class 'com.atlassian.jira.user.BridgedDirectoryUser' to class 'com.atlassian.jira.user.ApplicationUser'

        at TS-HardwareSale-AbverkaufFreigeben.run(TS-HardwareSale-AbverkaufFreigeben.groovy:7)

 

 

i dont know why but this works

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.issue.comments.CommentManager

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.user.*;

 

ComponentManager compManager = ComponentManager.getInstance()

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser();

CustomFieldManager customFieldManager = compManager.getCustomFieldManager()

 

//Zusammenbau vom String für den Kommentar

sourceFieldVal = ""+issue.getCustomFieldValue(compManager.getCustomFieldManager().getCustomFieldObject("customfield_10900")).displayName

sourceFieldVal = sourceFieldVal[1..-2]

 

sourceFieldVal = "Hallo *" + sourceFieldVal + "*\

\n\ndie Hardware steht für dich zum Abverkauf bereit.\

\n\nBitte gib uns in diesem Ticket durch *Kauf bestätigen* Bescheid, ob du die Hardware kaufen möchtest.\

\nAlle relevanten Informationen zur Hardware kannst du oben im Ticket einsehen und sind ebenfalls im Kaufvertrag enthalten.\

\nDer Kaufbetrag wird vom Gehalt abgezogen.\

\n\nNach deiner Bestätigung, wird HR-Confidential den Kaufvertrag im Ticket hinterlegen. Bitte diesen Kaufvertrag ausdrucken, unterschreiben\

\nund bei Technical Services vorbeibringen.\

\nAlternativ kannst du den unterschriebenen Kaufvertrag einscannen und im Ticket hinterlegen.\

\n\nGrü▒~_e\

\nTechnical Services"

 

CommentManager commentMgr = compManager.getCommentManager()

commentMgr = (CommentManager) compManager.getComponentInstanceOfType(CommentManager.class)

//Der wirkliche Kommentar

commentMgr.create(issue, currentUser, sourceFieldVal, true)

 

 

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Feb 15, 2018 in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

1,207 views 6 19
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot