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
Hi @Lynn Squire
After going through your description and subsequent comments, it appears you are trying to use ScriptRunner for Jira Cloud's Behaviour to update the value on a JSM project. Please clarify this.
I am saying this because you mentioned Typescript error and Typescript is used only for the Behaviour.
If yes, then unfortunately, at the moment, ScriptRunner for Jira Cloud's Behaviour doesn't support JSM Projects.
Please refer to this ScriptRunner for Jira Cloud Documentation for more information.
I am looking forward to your feedback and clarification.
Thank you and Kind regards,
Ram
Hello @Lynn Squire
Welcome to the Atlassian community.
Are you getting an error message to indicate failure, or are you not getting the result you expect?
I have not analyzed your code, but I found another post marked as Solved that talks about getting the working days difference between two date custom fields. The code there might help you (though the post is tagged as for Jira Server).
There is also an example from ScriptRunner of a script that calculates the days difference between two dates, though it does not include factoring in just business days.
https://www.scriptrunnerhq.com/help/example-scripts/calculate-difference-between-dates-cloud
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Error, something about the import function isn't allowed with Typescript.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is that the exact error message? If not can you provide the exact and full error message, including information about which line is causing the error?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This can't be a CLOUD Script, that's a DC Script as it has ComponentAccessor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online 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.