• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

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

Community Beginner ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

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; }

}}

 

cralis10_3-1592566721406.png

 

 

 

 

 

TOPICS
Acrobat SDK and JavaScript

Views

463

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 19, 2020 Jun 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...

Votes

Translate

Translate
Community Expert ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

LATEST

try67 was able to help me with the code! I had multiple errors and formating issues.

For example:

1. I used "sProcedure - sToday". try67 recommended "dateProcedure.getTime() - dateToday.getTime()" instead.

2. I had missing spaces between if and ().

3. I had placed a function thinking it was the reason why everything wasn't working. try67 pointed out I never called it... so it never executed. The function wasn't needed in what I was trying to accomplish. Also, the "event.rc = false" portion since I still want to continue with the date I input.

 

Thank you try67!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines