Hi, I´m trying to set up a post function script where the Enddate will be set to the end of the current month.
The actual script considers the currentdate value +30days.
Has anyone got an idea to change the +30 to endOfMonth?
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Date
import java.sql.Timestamp
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Logger
import org.apache.log4j.Level
// Manager
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
//Values
CustomField currentDate = customFieldManager.getCustomFieldObject("customfield_11808")
Timestamp currentDateValue = (Timestamp)issue.getCustomFieldValue(currentDate)
Date newDateValue = new Date(currentDateValue.getTime())
//Add 1 month
newDateValue.setMonth(currentDateValue.getMonth() +1)
//Update custom field
issue.setCustomFieldValue(currentDate, newDateValue.toTimestamp())
Hello @Jörg Friedmann,
You can use the following code to get end of the month. Just modify to parameters according to your currentDateValue variable.
GregorianCalendar calendar = new GregorianCalendar(2018, 8, 0);
Date date = calendar.getTime();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
// dateFormat.format(date) returns the last day of the month
Hi Thanks a lot but I´m running on an error
Can ypu please explain what you mean with currentDateValue vaiable?
I changed the date format to dd-MM-yy also but without success
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you want to set all dates to the current month's last day, you don't need use currentDateValue. I missunderstood, forget what I said:)
By the way did you import the date libraries?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I guess not.
I tried some modifcations but failed, Im not able to adapt your code to mine.
ALso what I do not understand is how your code interacts with the condition to set the new date of the issue to 1month in future.
Maybe my explanation was bad. Background is I have a workflow where every issue set to done will be cloned to a new issue. This new issue shall have the end date value changed 1month forward automatically.
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.