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; }
}}
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...
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...
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!
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.
Copy link to clipboard
Copied
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!!!