Hi again everyone,
I'm a new user of groovy, and I'm trying to learn its ins and outs but even this simple task has me stumped... I'm trying to concatenate a subtask's summary with it's created date.
From what I've read in Jira documentation / groovy documentation I'm using the following:
String summary = "issue.get("summary")" + " - " + "issue.get("created")
Can someone please help me understand what I'm doing wrong?
Thanks,
~Mike
HI @Michael
Type this code in your console and hit run.
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
IssueManager im = ComponentAccessor.getIssueManager()
MutableIssue issue = im.getIssueObject("SD-18") //Change Issue Key
return issue.summary + " - " + issue.created
Of course change the Issue key.
I hope it will help you.
Ravi
Hi again @Ravi Sagar _Sparxsys_ ,
That code works! But is there a way for it to auto-pull in the current issue ID where I had to manually input one? maybe something like getIssueID()?
Thanks,
~Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Michael
The code I shared works in the Console where you can test scripts or run ad-hoc scripts. If you use this script in let us say a Script field or listener. You will have Issue ID already available without declaring it.
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Ravi Sagar _Sparxsys_ ,
Just for clarification, what would the code look like that I would be inputting into a groovy script listener?
From what I'm seeing above within your code, the issue key would need to be changed every time a new issue was created.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Michael,
I don't know that there is a get(field) method like you're using, but there are ones such as getSummary(), getCreated(), etc. (which can be shortened to issue.summary and issue.created, etc.).
You've also got your double quotes a bit mixed up. Try the following, and see https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/Issue.html for more information about what you can do.
String newSummary = issue.summary + " - " + issue.created
That'll get the string you seek, and then you'll then need to update your issue with the revised summary.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Payne
How would the code look for updating the issue? and would it come before or after I input the:
String newSummary = issue.summary + " - " + issue.created
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Payne - I've tried the above string, and although it works within the script editor, it doesn't work when I go through the actual workflow. Is there something I need to input before the:
String newSummary = issue.summary + " - " + issue.created
Thanks,
~mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It depends upon where you are; if you're working with a ScriptRunner post function, for instance, issue is pre-defined. What exactly are you doing, and what do you mean by it doesn't work?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Payne
We are using a groovy script listener via the "workflow magic box" plugin in order to append the creation date to all parent/subtask tickets for our Jira data center instance.
When I input the exact code above into the groovy script editor, it works, but not when we try to trigger the code via a "issue.created" event, it doesn't append the creation date. (see screenshot)
Thanks,
~mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, OK. You're merely assigning the concatenated string to a variable, but you're not updating the issue. You need to do something like:
issue.summary = newSummary
That may work, but if not, you need to do something like that. That's what I said in my original response: That'll get the string you seek, and then you'll then need to update your issue with the revised summary.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Payne
So for example, if I want to concatenate the entered summary with the creation date of the issue, I'd need to type in the following:
issue.summary = issue.summary + " - " + issue.created
Is that correct?
Thanks again,
Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try it. I'm not sure if it's that simple. If not, you'll need to explore how to update an issue with your add-on.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Payne
I'll probably have to ask the plugin people for help, as that didn't seem to work either :(.
Thanks for the help!
Mike
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.