Forums

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

Check in two Date custom fields if the issue is created between 8-6pm and from Monday-Friday

Pavan Chiti October 30, 2021

Hi all,

I have a requirement in our project. We have 3 custom fields Start Date(Date field), End Date(Date field) and Outside Window(Check box). If the date selected in Start Date and End Date fields is between 8 AM - 6 PM and from Mon-Fri then Outside Window should be enabled and this requirement is for the Create Screen. 

Can someone help me with this requirement.

 

2 answers

1 accepted

2 votes
Answer accepted
Ravi Sagar _Sparxsys_
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.
October 31, 2021

Hi @Pavan Chiti 

You would need an app like ScriptRunner, it has a behaviour functionality which can let you add this dynamic features on the create issue screen. Take a look at some sample scripts as well.

Ravi

1 vote
Pavan Chiti November 3, 2021

My apologies for not replying earlier.

I was working on the ScriptRunner behavior script and was able to get the expected result.

I just started using ScriptRunner and let me know if this script is good enough.

Below is the script I used.

 

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import java.util.Date
import java.util.Calendar

def startDateCF = getFieldByName("Start Date")
def startDateValue = startDateCF.getValue() as Date
def endDateCF = getFieldByName("End Date")
def endDateValue = endDateCF.getValue() as Date
def outsideCF = getFieldByName("Outside Window")
outsideCF.setReadOnly(true)


if (startDateValue.getAt(Calendar.DAY_OF_WEEK) in [Calendar.SATURDAY, Calendar.SUNDAY])

outsideCF.setFormValue(['No'])
else {
outsideCF.setFormValue(['Yes'])
}

if (startDateValue.getAt(Calendar.DAY_OF_WEEK) in [Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY])
if (startDateValue.getAt(Calendar.HOUR_OF_DAY) > 8 || (startDateValue.getAt(Calendar.HOUR_OF_DAY) < 18)

outsideCF.setFormValue(['Yes'])

else {
outsideCF.setFormValue(['No'])
}
if (endDateValue.getAt(Calendar.DAY_OF_WEEK) in [Calendar.SATURDAY, Calendar.SUNDAY])

outsideCF.setFormValue(['No'])
else {
outsideCF.setFormValue(['Yes'])
}

if (endDateValue.getAt(Calendar.DAY_OF_WEEK) in [Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY])
if (endDateValue.getAt(Calendar.HOUR_OF_DAY) > 8 || (endDateValue.getAt(Calendar.HOUR_OF_DAY) < 18)

outsideCF.setFormValue(['Yes'])

else {
outsideCF.setFormValue(['No'])
}

Ravi Sagar _Sparxsys_
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.
November 3, 2021

Very nice. Well if it works then all good. Just add some error handling for null values but overall looks good.

Pavan Chiti November 5, 2021

Thank you, I'll add the null values in the script.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events