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,300,161
Community Members
 
Community Events
165
Community Groups

Date value should be selected after X days if I select a value in above dropdown field

We have Location field as drop-down field and date field. here we need if I select value XXX from Location the date field should be selected after 10 days and If I select YYY in the location the date field should be selected as 5 days after the current date. 

We are using JMWE any script can be shared which suits for this condition

Thanks,

Ajay

1 answer

1 accepted

0 votes
Answer accepted

Hi @Ajaygoud Gaddam ,

you can use a Set Issue Fields post-function, select the date field as the field to set, and use a Nunjucks script like this:

{% if issue.fields.customfield_12345.value == "XXX" %}
{{now | date('add',10,"days") | date}}
{% elif issue.fields.customfield_12345.value == "YYY" %}
{{now | date('add',5,"days") | date}}
{% else %}
{{now | date('add',1,"days") | date}}
{% endif %}

Hi @David Fischer _Appfire_ ,

Thanks for the prompt response.

Here is some more info for your understanding. 

* The date field is mandatory in the Create screen, so hope it should be resols with validation

* The date field should not be filled automatically to the 10, 5 days it should be greater than 10, 5 day of current date and it should be filled within creating the ticket.

It should show an error if they select within the range.

Hope this will help with the next suggestion.

Thanks,

Ajay

Oh, so if I understand correctly, you're trying to validate the field, not set it, correct?

In that case, you need to create a Build-your-own Validator with a Jira Expression like this:

!issue.customfield_12345 || !["XXX","YYY"].includes(issue.customfield_12345.value) ||
issue.customfield_12345.value == "XXX" && issue.customfield_67890 > new CalendarDate().plusDays(5) ||
issue.customfield_12345.value == "YYY" && issue.customfield_67890 > new CalendarDate().plusDays(10)

where  customfield_12345 is the single-select field and customfield_67890 is the Date (only) custom field.

Hi @David Fischer _Appfire_ Thanks again,

As I am completely new to scripting I didnt see were i am missing something. In the JMWE validator i have tested the expression and it shown the true valu as it fine but while creating the ticket even if we select date not in range too the ticket is not being submitted and showing the custom error what we added in the validator error.

attaching the script and logs down


!issue.customfield_10059 || !["Beijing","Berlin","Hamburg"].includes(issue.customfield_10059.value) ||
issue.customfield_10059.value == "Beijing" && issue.customfield_10060 > new CalendarDate().plusDays(5) ||
issue.customfield_10059.value == "Berlin" && issue.customfield_10060 > new CalendarDate().plusDays(10)

create.pngerror.pngscrpt.png

As I tried date field above and my requirement should be for date and time field will you please suggest next expression for date and time field.

Thanks,

Ajay

Hi @Ajaygoud Gaddam ,

since it's a Date custom field, Jira Expressions don't return a CalendarDate object but a string (for no good reason).

Try this:

!issue.customfield_10059 || !["Beijing","Berlin","Hamburg"].includes(issue.customfield_10059.value) ||
issue.customfield_10059.value == "Beijing" && new CalendarDate(issue.customfield_10060) > new CalendarDate().plusDays(5) ||
issue.customfield_10059.value == "Berlin" && new CalendarDate(issue.customfield_10060) > new CalendarDate().plusDays(10)

Many Thanks @David Fischer _Appfire_ ,

It works for Date custom field could you please suggest what should be added to the above expression for Date and time field.

It would be really appreciated if I would get expression for Date and time custom field.

Thanks again in advance.

Ajay

Hi @Ajaygoud Gaddam ,

I'm glad it works. For a date/time custom field, just replace CalendarDate with Date everywhere.

Super It works, Thanks for the help @David Fischer _Appfire_ 

Suggest an answer

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

An update on Jira Software customer feedback – June 2022

Hello Atlassian Community! Feedback from customers like you has helped us shape and improve Jira Software. As Head of Product, Jira Software, I wanted to take this opportunity to share an update on...

73 views 1 3
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