Skip to main content
New Participant
June 19, 2020
Answered

Date Range Validation with Alert (Within 2 weeks, 1 week, etc.)

  • June 19, 2020
  • 1 reply
  • 861 views

Hello, novice here. I've attempted to pull information from two different solutions (credit try67 & johnk12695043 Validating Dates conversation). I assume I need the Today field to succeed, but if I don't, please let me know. I'm hoping I don't need it. Thank you for your attention!

 

Today Field is using a script :"this.getField("Today").value = util.printd("m/dd, ddd", new Date());"

 

My goal is to have two different alerts popup separately or simultaenously if it fulfills the following criteria: procedure date chosen is less than or equal to 2 weeks and 1 week from today's date. I'm using a Custom Date Text Field in the format of m/dd, ddd to give me (6/19, Fri format output).   Was my attempt at this a complete fail?

 

Below is the validation script I attempted to run.

var sToday = this.getField("Today").value;

var sProcedure = this.getField("Procedure").value;

if(sToday.length && sProcedure.length) {

var dateToday = util.scand("m/dd, ddd",sToday);

var dateProcedure = util.scand("m/dd, ddd",sProcedure);

var nMilliResult = (sToday - sProcedure) * 1;

if (nMilliResult < 1209600000) {

app.alert("C19 Admin RN Order < 2 weeks");

event.rc = false;

if (nMilliResult < 604800000) {

app.alert("C19 Screening Questions < 1 week");

event.rc = false; }

}}

 

 

 

 

 

 

This topic has been closed for replies.
Correct answer try67

If this is the validation script of "Procedure" then change this line:

var sProcedure = this.getField("Procedure").value;

To:

var sProcedure = event.value;

 

I would also reverse the order of the alerts and add an "else" between them. If the difference is under one week then it's obviously also under two weeks, so there's no need to show both...

1 reply

try67
try67Correct answer
Adobe Expert
June 19, 2020

If this is the validation script of "Procedure" then change this line:

var sProcedure = this.getField("Procedure").value;

To:

var sProcedure = event.value;

 

I would also reverse the order of the alerts and add an "else" between them. If the difference is under one week then it's obviously also under two weeks, so there's no need to show both...

cralis10Author
New Participant
June 20, 2020

I wasn't able to achieve any type of response/action with the original code or with the changes </3. To be continued! I'll have to research more. Thanks for the response!

try67
Adobe Expert
June 20, 2020

Did you check the JS Console for error messages? I'll need to see the actual file to help you further.