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

How to specify the range in a Date Range Picker? Edited

Dears,

for request we need to add a "due date". (by when they want something to be done)

Depending on the request we can already say that the earliest can be today + X days.

How can this be done?

 

Kind regards,

 

Matt

2 answers

1 accepted

0 votes
Answer accepted
Jack Community Leader Sep 20, 2017

@Matthew Van Kuyk, let me restate what I think you are asking for to be sure I am following. In the end I think you will need something like Scriptrunner or maybe Automation for JIRA to make this work.

You want to create a custom 'due date' field and you want to automatically set the default to "today + x days" based upon Issue Type.

example:

Task = today +5d

Bug = today +2d

Hi Jack,

 

Thanks you doe your reply. It is not the field itself that should be x + 5days. It should be the date picker which should make all days available from x+5days on. Additionaly a script should be ran to check if the value entered is indeed in the correct range (that I can do with script runner).

Kind regards,

Matt

Jack Community Leader Sep 25, 2017

Ok so you want to restrict the first date of a date picker?

So if i create an issue on 9/1/2017 the first date I can pick for this field should be 9/6/2017?

If so, I’m unsure how to accomplish. I’m unsure if there is an addon that could do this. It might mean changing the code, creating a specialize date picker. Hopefully someone w/ more knowledge could chime in here. @Adaptavist Nic, any thoughts on this one?

I don't think even Behaviours (part of Scriptrunner) can get into the display at that depth.  You could default the value and do the validation on create/transition with Behaviours and Scripts, but limiting the calender would require dedicated code I think.

Jack Community Leader Sep 25, 2017

Thanks for chiming in Nic. this was what I was expecting but unsure.

Nic, Jack,

thank you for your valuable input. As a workaround I have created a validation script which will check if the selected date is in the correct range.

import com.opensymphony.workflow.InvalidInputException;
import com.atlassian.jira.component.ComponentAccessor;

try{
    //set the value of the customer request type of Request Internal Move
    def requestInternalMove= "sd/d28a8b4a-343c-453c-9e87-68a1f7b2710d"
    
    def issueManager = ComponentAccessor.getIssueManager()
    def customFieldManager = ComponentAccessor.getCustomFieldManager()
    def cf = customFieldManager.getCustomFieldObjectByName("Customer Request Type")
    def cFieldValue = issue.getCustomFieldValue(cf)
    log.error "Customer Request Type: " + cFieldValue;

    if(cFieldValue.toString().equals(requestInternalMove)){
        //Set de amount of dates needed
        int noOfDays = 14; //i.e two weeks
        Calendar calendar = Calendar.getInstance();          
        calendar.add(Calendar.DAY_OF_YEAR, noOfDays);
        Date date = calendar.getTime();

        //Check if the due date is later than the 2 weeks
            if (issue.dueDate?.before(date)) {
                invalidInputException = new InvalidInputException("2 weeks are required to provide this service, please provide a date after " + date)
            }
    }
}catch(Exception ex){
    invalidInputException = new InvalidInputException("An error ocured please contact the helpdesk")
    log.error ex.getMessage()
 
}

Kind regards,

Matt

Matt:  where did you put that script?  I'ma  bit new to this and need something similar

 

Thanks

I have the same questions as @tim nixon since I'm also new to this.

A validator script can be placed on the disk on the server (usually under <jira home>/scripts), and then referred to in the workflow validator function, or written directly inside the validator function.

It would be quite handy if the date picker itself (the calendar) could be limited to only show dates after today() or today(+2d).. I dont think that's possible.. but we simply enforce the date being >=today() in a validator.  We ran into an issue with that and the users timezone. Basically at 9:30pm the user could not set the date to today. The validator thought it was already tomorrow..

zhangdan I'm New Here Jul 04, 2021

Has your idea been realized? I also want to realize that the optional range of date picker can be controlled, and the maximum selection time is the current time + 30 days

Suggest an answer

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

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

226 views 2 15
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