Hi,
using script-runner plugin I would like on post action to the change the Summary on the fly, according to some other fields
ex:
I'm a newbe and any link to
will be welcomed
thanks
Community moderators have prevented the ability to post new answers.
I'm also a beginner.
Groovy is Java. No need to be pro, but you should have basic knowledge of object oriented programming.
First thing I did is looking at some basic scripts. When you create a script post function in a workflow step, there are some built-in (canned) scripts that you can use. Once you select a canned script, you will see a link to 'view source'. View the source and study.
Secondly, for API reference I referred to the following link:
https://developer.atlassian.com/static/javadoc/jira/6.0.6/reference/packages.html
Start with modifying some canned scripts to cater your requirements. Definetely you will change it to what you need, while gaining knowledge.
That's how I learned. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks you Sameera. Your tips are useful. And the link you provided is far better than the one I found (https://docs.atlassian.com/jira/latest/com/atlassian/jira/ComponentManager.html)
I have 2 questions, maybe you can help.
I come from "compiled world" (C#) where you have proper editor to help you programming ;) web & script world is a total nightmare for me.
thanks
Julien
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you type GroovySystem.getVersion() into the script console you get the version.
I personally have IDEA installed on my local machine as groovy script IDE and I'm "debugging" through log commands in the scripts to print useful information to the log file (catalina.out).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is your server Linux or Windows?
Regarding your interpretation of API redference, for example, issue summary:
API Reference: https://developer.atlassian.com/static/javadoc/jira/6.0.6/reference/com/atlassian/jira/issue/Issue.html
You have to import com.atlassian.jira.issue.Issue (Interface is Issue) and call the getSummary() method. That's it.
You are coming from 'compiled world' but seems you already have OOP knowledge. Script stuff will be much more easier but it's not going to give you the 'Microsoft' feeling.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You could take a look at my answer here: https://answers.atlassian.com/questions/257042/groovy-starter-ressources
You can access the issue summary through issue.getSummary() in a workflow postfunction. The components you get through issue.getComponentObjects(). So your workflow postfunction should be like this
issue.summary += " - " + issue.componentObjects?.join('/')
Look for "Groovy Beans" in the Groovy documentation to see why you could write issue.summary instead of issue.setSummary() or issue.getSummary(). The question mark is the "Safe Navigation Operator (?.)" which prevents Null Pointer Exceptions in case of undefined results.
Maybe you want to test first if there are components selected, but I leave that up to you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Many Thanks for those details Henning.
I guess the reasons for direct access to summary is
"If you access a property from within the class the property is defined in at compile time with implicit or explicit this (for example this.foo, or simply foo), Groovy will access the field directly instead of going though the getter and setter."
I looked at the source of a canned script but I think there are to much infomation at a time. My guess s that I don't need all the includes in my own exemple. My class should be very simple.
I have 4 very basics questions
Appreciate your help but I keep looking by myself at the same time of course.
Julien
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The log file you suggested is correct.
The script console is a menu point in the plug in section in JIRA. Type "gg" on any JIRA screen, than type "console" and you will see the corresponding point.
For basic scripts you don't have to create/extend any classes or write methods. Write what you want to do. That's a benefit of a scripting language like Groovy.
For the Windows environment I couldn't help you. I would try to write the path like you would write it on Windows. If it doesn't work you will see error messages in the log.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi guys.
I did it eventually !
import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.resolution.Resolution import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField //retrieve the custome field 'Sous-Projet' CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() CustomField ssprjt = customFieldManager.getCustomFieldObjectByName("Sous-Projet") //retrieve a specific issue //IssueManager issueManager = ComponentManager.getInstance().getIssueManager() //MutableIssue myIssue = issueManager.getIssueObject("BP_19") MutableIssue myIssue = issue //amend the issue summary myIssue.summary = "[" + String.valueOf(myIssue.getCustomFieldValue(ssprjt)) + "] - " + myIssue.summary //return myIssue.summary
I first debug it with a real issue and then implement a post action successfully.
Nevertheless I a bit confused:
MutableIssue myIssue = issue
I spent some time to figure out on the Web how to specify the current issue. Where is that clearly written in the documentation
my post action is on the first transition "create". I had to place my post action on the top position before "Creates the issue originally." and this is not clear to me. Remarks by Henning on this case helped me.
Anyway thanks again for your help
cheers
Julien
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
On this page there is a hint for issue: "In each case, the plugin will provide the current issue and transientVars in the binding. That means you can refer to them using these variables." Another place to look for such bindings are the examples.
While creating the issue, the issue object exists but is not saved to the database before the "Creates the issue originally" happens. If you modify the issue object before "Creates the issue originally"your changes are saved in the moment "Creates the issue originally" happens. If you modify the issue object after "Creates the issue originally", you have to take care by yourself to save the changes. In this case "issueManager.updateIssue()" should be called. Or you use the safest way (from API usage point of view) to change the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning & Sameera,
I achieved to test a basic script (in the script consol) to understand how things work.
import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.resolution.Resolution IssueManager issueManager = ComponentManager.getInstance().getIssueManager(); MutableIssue myIssue = issueManager.getIssueObject("BP-19") myIssue.summary += "-" + myIssue.getResolutionObject()?.getName() return myIssue.summary
I will close definitively my ticket soon
Many thanks to both of you for your great help.
Cheers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.