Add + 1 day to Date field

GS1337 September 24, 2019

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

1 answer

1 accepted

1 vote
Answer accepted
Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2019

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())

 

GS1337 September 24, 2019

Thanks alot it worked as intended :)

Suggest an answer

Log in or Sign up to answer