I can't figure this one out and it probably is easy for most of you. We want to create a script at the create issue step in the workflow that prevents an issue from being created using JSM form if that date is less than 3 business days in the future. We can figure out how to do 3 DAYS in the future but BUSINESS DAYS is giving me headaches.
Anyone have a script they have used in the past I can steal? This is for JIra cloud. Again, this would prevent an issue from being created, would throw an error for the user if the date is less than 3 business days in the future using Scriptrunner.
This is the code I have so far, but it is failing. This is for Jira Cloud.
import java.time.LocalDate
import java.time.ZoneId
import java.time.DayOfWeek
import com.atlassian.jira.component.ComponentAccessor
// Get your custom field (Date Picker) — update with your actual field ID
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_12345")
def dateValue = issue.getCustomFieldValue(customField)
if (!dateValue) {
return false // Fail validation if no date was provided
}
// Convert java.util.Date to java.time.LocalDate
def targetDate = dateValue.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()
def today = LocalDate.now()
// Count business days between today and the selected date
int businessDays = 0
def current = today
while (current.isBefore(targetDate)) {
if (!(current.getDayOfWeek() in [DayOfWeek.SATURDAY, DayOfWeek.SUNDAY])) {
businessDays++
}
current = current.plusDays(1)
}
// Pass only if target date is at least 3 business days ahead
return businessDays >= 3