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?
Type this code in your console and hit run.
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.
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.
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)
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.
I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events