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

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

Ajaygoud Gaddam April 28, 2022

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

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 28, 2022

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 %}
Ajaygoud Gaddam April 28, 2022

Hi @David Fischer ,

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

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 28, 2022

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.

Ajaygoud Gaddam May 2, 2022

Hi @David Fischer 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

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 2, 2022

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)
Ajaygoud Gaddam May 3, 2022

Many Thanks @David Fischer ,

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

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 3, 2022

Hi @Ajaygoud Gaddam ,

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

Ajaygoud Gaddam May 3, 2022

Super It works, Thanks for the help @David Fischer 

TAGS
AUG Leaders

Atlassian Community Events