Forums

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

Force the users to add a date which is Now + 5 business days.

Susann Ivarsson May 21, 2024

We have a date customfield for "Desired delivery date". Our standard delivery time is 5 business days which is communicated lots of time but despite that they usually choose a date earlier than 5 days.

I want to create a behaviour to force the users to add a date which is 5 days or more from now. If they pick a date which is less than 5 days from now they will receive an errormessage.

 

1 answer

0 votes
Florian Bonniec
Community Champion
May 22, 2024

Hi @Susann Ivarsson 

 

You could use something like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

def earliestDate = new Date().plus(5)

def dateField = getFieldById(fieldChanged)
def dateValue = dateField.value as Date

if (dateValue < earliestDate ){
dateField.setError("Date cannot be earlier than (${earliestDate})") 
}

Regards

Susann Ivarsson May 27, 2024

Hi,

It works perfect but how do I excludes the weekdays?

Florian Bonniec
Community Champion
May 27, 2024

You could try something like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

def earliestDate = new Date().plus(5)

def dateField = getFieldById(fieldChanged)
def dateValue = dateField.value as Date

if (dateValue < earliestDate ){
dateField.setError("Date cannot be earlier than (${earliestDate})")
}


def addBusinessDays(Date date, int workdays) {
if (workdays < 1) {
return date;
}

def result = date;
int addedDays = 0;
while (addedDays < workdays) {
result = result.plusDays(1);
// Check if it's a weekday
if (!(result.getDayOfWeek() == DayOfWeek.SATURDAY ||
result.getDayOfWeek() == DayOfWeek.SUNDAY)) {
++addedDays;
}
}
return result;
}



Regards

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events