Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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

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'])
}

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

Next level incident management in Jira Service Management

Hello Atlassian Community! We’re thrilled to announce some exciting changes to incident management in Jira Service Management Cloud, in order to give your teams extra muscle during incidents, and ...

1,674 views 21 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you