I have a Date custom field in which the user can pick the date he wantes , however the problem is that he can choose a date that's already passed ( for example we are at 17/06 but he can choose the date 15/06 ) how can i disable that for the user and allow him to only chose starting from the current date .
Hello @Kou Ssi ,
Indeed, this can be done using Power Scripts and SIL Validator. Here is an example of such a script:
string format = "dd-MM-yyyy ";
string errorMsg = "You cannot select date in the past!";
date selected_date=getInput("customfield_18400");
if(formatDate(selected_date, format) < formatDate(currentDate(), format)) {
return false, "customfield_18400", errorMsg;
}
You need to replace customfield_18400 with your custom field id. Also, to allow users to select a date that is the current day, I had to add extra formatting, because by default if you select today's date in the Jira Date Picker field, the output behind will contain also hours and minutes like 2023-07-07 00:00:00, and currentDate() output will be something like 2023-07-07 11:08:41, so it will also compare time part and will not allow you to select current date.
So if you select the date in the past, you`ll get the error message near the field:
And on top of the page:
Hope this helps!
Anna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Kou Ssi
If you have ScriptRunner, and you want to limit date, while issue is creating, you can use Validator, or Behaviour with groovy script, that checks, that date is larger then current moment.
Something like this, for Validator:
Date now = new Date()
return issue.created > now.toTimestamp()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As far, as I know, SIL has Validators too. I ant very good familiar with it, but I think, you can check, that date entered is larger than now with next code:
return getInput("customfield_10001") > currentDate()
Found methods here:
https://anovaapps.atlassian.net/wiki/spaces/PSJ/pages/1131021259/getInput
https://anovaapps.atlassian.net/wiki/spaces/PSJ/pages/1129775385/currentDate
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.