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
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 ,
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ajaygoud Gaddam ,
I'm glad it works. For a date/time custom field, just replace CalendarDate with Date everywhere.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.