Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Add + 1 day to Date field

GS1337
Contributor
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 edited

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
Contributor
September 24, 2019

Thanks alot it worked as intended :)

Dhiraj Kr_ Gupta
Contributor
June 6, 2024

How to do this in confiform

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25 europe, atlassian event, barcelona 2025, jira, confluence, atlassian intelligence, rovo, ai-powered collaboration, developer tools, agile teams, digital transformation, teamwork solutions, atlassian conference, product announcements

🌆 Team '25 Europe registration is now open!

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 now
AUG Leaders

Atlassian Community Events