We have four change request types. For one of the request type (Normal), we need a validation for custom date field (Planned Start Date) where there should be an error message if user tries to enter a date that is less than 7 calendar days. I tried using Scripted Groovy Validator, but not receiving the error message. Please see attached screenshot.
Can anyone help with this?
I would like the code to be executed and the error to be displayed when somebody is entering a value for Planned Start Date field in the Create screen. (Only for the Normal request type)
String, Used to separate the day, month, ... callback validator validator as shown in the Custom format example below.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Pavan Chiti
You can use Jira's native validator "Compare two dates" and write something like the one below:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But if you need the groovy script for JMWE, then I would go with something like this
(!!issue.customfield_10010 && issue.customfield_10010.requestType.name == "Normal") && (!!issue.customfield_10045 && new Date(issue.customfield_10045) >= new Date().minusDays(7))
Where customfield_10010 is the request type and customfield_10045 is your Planned Start Date field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much for providing the code .
I inserted the text provided. But still no luck.
Below is the screenshot of the error.
Please let me know how to fix the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this @Pavan Chiti:
issue.get("customfield_10303")?.name == "Normal" && (issue.get("Planned Start Date/Time") >= now.minus(7))
In case I've messed up the names of your custom fields, please fixed them! :)
I've tried the above on Jira server and it works. Do let me know though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Alex Koxaras -Relational- for looking into this.
Code executed with no errors, but receiving expected error message for all request types (not just Normal) and irrespective of any date entered in Planned Start Date field.
My use case was that we need an error message displayed for custom date field (Planned Start Date) , if user tries to enter a date that is less than 7 days from the current time of Change creation and this is only for Normal Change Request Type.
For the validator solution provided earlier, I believe we can't use it because we can't the Request Type = Normal.
Is this the most appropriate plugin for this scenario or is there any other plugin that we should use?
Any help is appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Pavan Chiti
It seems that I've missed an if statement. Try the following please:
if (issue.get("customfield_10303")?.name == "IT help" && issue.get("Planned Start Date/Time") >= now.minus(7)){
return false;
} else {
return true;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Alex Koxaras.
Code executed with no errors, but not receiving the expected error message when a date is entered in Planned Start Date field.
My use case is when a date within 7 days is entered in Planned Start Date field from the current date. For example if I am creating the Change today and if I am entering any date from today to 10/13, an error should be displayed and if any date after 10/13 is entered no error should be displayed.
Attached is the screenshot for the text I entered.
Can you help?
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.
Maybe something like this?
if (issue.get("customfield_10303")?.name == "IT help" && (issue.get("Planned Start Date/Time") >= now.minus(7) && issue.get("Planned Start Date/Time") <= now )){
return false;
} else {
return true;
}
I mean you can find the answer yourself about this Pavan:
So this is the interval which you want an error message to appear. All other values will be considered as correct.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Code executed perfectly but not receiving the expected error message for any date and Request type is entered in Planned Start Date field.
Code is returning true for both request types Normal and Standard even when the Change for created for only Normal Change.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Pavan Chiti where do you want this code to be executed? Like in a transition, or whenever somebody is changing the value of that field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would like the code to be executed and the error to be displayed when somebody is entering a value for Planned Start Date field in the Create screen. (Only for the Normal request type)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you add this script as a validator on the create transition?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, below is the screenshot that shows the code was added into the validator with the error message that needs to be displayed for the field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Pavan Chiti
Try to make the field mandatory. I can confirm that I've tested it and it works fine!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I apologize for not replying earlier. I got struck into deployment issues and had to go off the track. Our requirements are changed now and we are not using the portal anymore.
New requirements -
We would be using the Create button for creating Change.
We have 2 custom fields Planned Start Date/Time and Planned End Date/Time.
An error should be displayed if Planned End Date/Time is on or before Planned Start Date immediately before we move to the next field. This should happen on the same screen before creating the Change.
I am assuming we need to write a script for this requirement.
Can you please help me on how to work on this.
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.