Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

groovy script for concatenating the summary and created date of a ticket?

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

2 answers

0 votes
Ravi Sagar Community Leader Mar 12, 2020

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 ,

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

Ravi Sagar Community Leader Mar 16, 2020

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

Hi again @Ravi Sagar ,

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.

0 votes
Payne Community Leader Mar 12, 2020

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.

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

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

Payne Community Leader Mar 18, 2020

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?

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)

screenshot of script running without errors.png

Thanks,
~mike

Payne Community Leader Mar 18, 2020

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.

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

Payne Community Leader Mar 18, 2020

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.

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

334 views 9 7
Read article

Community Events

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

Events near you