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

Custom Date field validation to check if it is less then 7 calendar days

Pavan Chiti October 4, 2021

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?screenshot.PNG

3 answers

0 votes
Pavan Chiti October 8, 2021

@Alex Koxaras _Relational_ 

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)

0 votes
Ruth T_ James
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 5, 2021

String, Used to separate the day, month, ... callback validator validator as shown in the Custom format example below.

 

greatpeople me kroger

0 votes
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 5, 2021

Hi @Pavan Chiti 

You can use Jira's native validator "Compare two dates" and write something like the one below:

compare dates.png

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 5, 2021

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

Pavan Chiti October 5, 2021

Thank you very much for providing the code .

I inserted the text provided. But still no luck.

Below is the screenshot of the error.

Capture1.PNG

Please let me know how to fix the issue.

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 5, 2021

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. 

Pavan Chiti October 5, 2021

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.

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 6, 2021

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;
}
Like Peter likes this
Pavan Chiti October 6, 2021

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?

Pavan Chiti October 6, 2021

Looks like I missed the screenshotDate.PNG

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 6, 2021

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:

  • now.minus(7) = 7 days ago
  • now = eerr... now

So this is the interval which you want an error message to appear. All other values will be considered as correct.

Pavan Chiti October 7, 2021

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.

Normal.PNGStandard.PNGChange-summary.PNG

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 8, 2021

@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?

Pavan Chiti October 8, 2021

@Alex Koxaras 

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)

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 8, 2021

Did you add this script as a validator on the create transition?

Pavan Chiti October 8, 2021

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.

screenshot1.PNG

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 8, 2021

Hi @Pavan Chiti 

Try to make the field mandatory. I can confirm that I've tested it and it works fine!

error.png

Mohan Rao October 26, 2021

Hi

Pavan Chiti October 26, 2021

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events