Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,554,909
Community Members
 
Community Events
184
Community Groups

Target Date Weekdays Only (Behaviour)

Edited

Hi

I have the below script which works on a date field called "Target Date"

It requires tickets being created to have a 3 day leading time so they cannot set the target date to be today or in following 2 days as this is unrealistic expectation for delivery.

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.user.util.UserUtil

import java.util.Date.*

      

import java.text.SimpleDateFormat

import java.sql.Timestamp

import java.text.DateFormat

  

duedatefield = getFieldByName("Target Date")

Date duedatevalue = (duedatefield.value as Date)

  

//today

def today = new Date()

 

def noticket = new Timestamp((new Date() +3).getTime())

  

  

if(duedatevalue.getTime() < noticket.getTime()){

    duedatefield.setError("Note: All tickets require a 3 day leading time, if your ticket is urgent and is required to be actioned the same day please contact xxx@yyy.com")

} else{

    duedatefield.clearError()

}  

 

I wanted to see if anyone can help me edit this script to only work on weekdays, ie - It will not factor in Saturday or Sunday. A example of the problem would be a user creating a ticket on Friday and setting the target date to be following Monday, where the team does not work the weekend, the earliest in this scenario should be the following Wednesday. 

 

Thanks for any advice

Rich

 

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 29, 2023

Hi @Richard Duffy

For your requirement, you can try something like this:-

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def targetDate = getFieldById(fieldChanged)

def calendar = Calendar.instance
def map = [1: 3, 2: 3, 3: 3, 4: 5, 5: 5, 6: 5, 7: 4]
calendar.add(Calendar.DATE, map[calendar.get(Calendar.DAY_OF_WEEK)])

targetDate.clearError()

if (targetDate.value) {
def targetDateValue = targetDate.value as Date

if (targetDateValue < calendar.time) {
targetDate.setError('Note: All tickets require a 3 day leading time, if your ticket is urgent and is required to be actioned the same day please contact xxx@yyy.com')
}
}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Behaviour configuration:-

image1.png

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

This is brilliant and works well.

How would I adapt this for 2 day lead time?

Can you offer a short explanation of how the below line works? I think I understand what is happening but just want to be sure.

def map = [1: 3, 2: 3, 3: 3, 4: 5, 5: 5, 6: 5, 7: 4]

Thanks so much again, great work!

Richard 

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 30, 2023 • edited

Hi @Richard Duffy 

Great to hear the solution worked for you. :-)

In your last comment, you asked:-

How would I adapt this for 2 day lead time?

So in the example that I have given, the map is set to 3 days lead time, i.e.:-

def map = [1: 3, 2: 3, 3: 3, 4: 5, 5: 5, 6: 5, 7: 4]

So basically, the map's key 1 is for Monday, 2 for Tuesday and so on.

For values, Monday till Wednesday, it is set to 3, while for Thursday, Friday, Saturday and Sunday, the value is set to 5 and 4, respectively, to exclude the weekends.

If you want to switch it to two days lead time, you will basically have to subtract all the values in the map by 1, i.e. it should be:-

def map = [1: 2, 2: 2, 3: 2, 4: 4, 5: 4, 6: 4, 7: 3]

I hope this helps to answer your question. :-)


Thank you and Kind regards,

Ram

HI Ram,

Yes thats what I thought, what was confusing me was Jira considers Sunday to be the first day of the week not monday.

All good, thanks =)

Rich

Suggest an answer

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

Atlassian Community Events