You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
I'd like to know if the following can be done:
When creating a ticket that has two customfields "Planned Start" and "Planned End", automatically set the first day of the month in the first field and the last day of the month in the second field regardless of the month in which the issue was created. The values should be of type Date.
So far I have no idea how this can be done or if it can be done at all, so I'd like to ask the community.
Maybe Calendar class can help with it.
If you have any ideas on how this can be done, please share.
Unfortunately, I have done very little with dates and time, but the feeling is that this case is doable.
Automation is also available for Server/DC, you either need to get it as a separate app (or I think it might also be part of JSM).
But it should also definitely be possible with groovy/scriptrunner.
I have never liked working with the Calendar class.
Here is how I would calculate those dates:
def today = new Date()
def firstOfCurrentMonth = today.toLocalDate().withDayOfMonth(1).toDate().toTimestamp()
def lastOfCurrentMonth = today.toLocalDate().plusMonths(1).withDayOfMonth(1).minusDays(1).toDate().toTimestamp()
I'm outputting both as "timeStamp" since that's what date/time fields require
Thank you for correcting me.
Unfortunately, we don't have the plugin and won't be able to install it for our JIRA, so I'm using Scriptrunner as best I can.
Thank you very much for the script; it works great and fits my requester's requirements.
I've been experimenting with the methods and noticed that you can do more with Date than Calendar, but I could be wrong due to my ignorance.
My post function looks like this for those who are interested:
currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// The day and time when the issue is created
// Using the variable above, we can find the first and last days of the month
firstDayOfCurrentMonth = today.toLocalDate().withDayOfMonth(
lastDayOfCurrentMonth = today.toLocalDate().plusMonths(
// Customfields of type Date
cfPlannedStart = ComponentAccessor.getCustomFieldManager()?.getCustomFieldObject(
cfPlannedEnd = ComponentAccessor.getCustomFieldManager()?.getCustomFieldObject(
// Set the above values in these fields
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false