Hi,
in a workflow postfunction via scriptrunner i want to add + 1 day to my "Target end" Date field. Can anybody help me with a script, i also need one that workds with custom field IDs not Object Names. ty
hello, if you want to simply add 1 day, place this one as the first postfunction in the list (or at least before the one that saves issue to db):
import com.atlassian.jira.component.ComponentAccessor
def customFieldObject = ComponentAccessor.customFieldManager.getCustomFieldObject(10101)
def dateValue = issue.getCustomFieldValue(customFieldObject)
dateValue += 1
issue.setCustomFieldValue(customFieldObject, dateValue)
just in case you want to skip weekends, here's a bit more complex version:
import com.atlassian.jira.component.ComponentAccessor
void addWorkDays(date, n) {
def i = 0
while (i < n) {
date.add(Calendar.DAY_OF_YEAR, 1)
if (!(date.get(Calendar.DAY_OF_WEEK) in [Calendar.SATURDAY, Calendar.SUNDAY])) {
i++
}
}
}
def customFieldObject = ComponentAccessor.customFieldManager.getCustomFieldObject(11900)
def dateValue = issue.getCustomFieldValue(customFieldObject)
def calendarValue = Calendar.instance
calendarValue.setTime(dateValue)
addWorkDays(calendarValue, 1)
issue.setCustomFieldValue(customFieldObject, calendarValue.time.toTimestamp())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Join the largest European gathering of the Atlassian Community and reimagine what’s possible when great teams and transformative technology come together. Plus, grab your Super Fan ticket now and save over €1,000 on your pass before prices rise on 3 June.
Register nowOnline 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.