Hi there,
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.
Thank you.
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:
import
com.atlassian.jira.event.type.EventDispatchOption
import
com.atlassian.jira.component.ComponentAccessor
def
currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// The day and time when the issue is created
def
today =
new
Date()
// Using the variable above, we can find the first and last days of the month
def
firstDayOfCurrentMonth = today.toLocalDate().withDayOfMonth(
1
).toDate().toTimestamp()
def
lastDayOfCurrentMonth = today.toLocalDate().plusMonths(
1
).withDayOfMonth(
1
).minusDays(
1
).toDate().toTimestamp()
// Customfields of type Date
def
cfPlannedStart = ComponentAccessor.getCustomFieldManager()?.getCustomFieldObject(
11700
)
def
cfPlannedEnd = ComponentAccessor.getCustomFieldManager()?.getCustomFieldObject(
11701
)
// Set the above values in these fields
issue.setCustomFieldValue(cfPlannedStart, firstDayOfCurrentMonth)
issue.setCustomFieldValue(cfPlannedEnd, lastDayOfCurrentMonth)
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Volodymyr
Using Automation rules, you can achieve this.
Provide details like when and what conditions do you want to execute this functionality.
Madhuri C
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @C Madhuri
As far as I remember, Automation is for Cloud, while I'm using Server and will be migrating to Data Center.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Volodymyr
You can install automation for Jira and it is a free app in both server and datacenter.
It will be easier to achieve this functionality using automation
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Chinthalapalli Madhuri
We are currently migrating to Data Center version, so my team isn't installing any plugins. Also, as far as I remember, A4J will be out of the box in the DC.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.