hello
since the update of the script runner plugin our groovy scripts which just place a comment in the ticket does not work anymore.
Version:
error.png
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
commanager.png
line25.png
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.
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.
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?
It looks like you're new here. Sign in or register to get started.