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

Custom Calculation Script - Set deadline date at least 5 working days after date of submission

Community Beginner ,
Nov 04, 2021 Nov 04, 2021

Hi all,

 

I have no basic knowledge of scripting and had only begun using Custom Calculation Script in Acrobat.

 

We have a Job Sheet that we have two Date fields on. One is the Date Submitted, and the other is Deadline. We need to have the Deadline date option to be at least 5 working/business days after the Date Submitted.

 

We currently have 

 

var s1 = this.getField("DATESUBMITTED_af_date").valueAsString; if (s1=="") event.value = ""; else { var d1 = util.scand("dd/mmm/yyyy", s1); d1.setDate(d1.getDate()+5); event.value = util.printd("dd/mmm/yyyy", d1); }

 

But this only sets the Deadline date 5 days after and there's no option to select a later date.


Any help would be much much appreciated!

 

Thanks!

TOPICS
Create PDFs , JavaScript
930
Translate
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 ,
Nov 04, 2021 Nov 04, 2021

Sorry, this is how the current script looks and not the mess above.

var s1 =

this.getField("DATESUBMITTED_af_date").valueAsString;

 

if (s1=="") event.value = "";

 

else {

    var d1 = util.scand("dd/mmm/yyyy", s1);

    d1.setDate(d1.getDate()+5);

    event.value = util.printd("dd/mmm/yyyy", d1);

}

Translate
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 ,
Nov 04, 2021 Nov 04, 2021

If you want to be able to change date manually in second date field (lets call it "Date2") use script in "DATESUBMITTED_af_date" as validation script and not custom calculation, and set "Date2" field to have date format also.

Something like this:

if (event.value == "") this.getField("Date2").value = "";
else {
var d1 = util.scand("dd/mmm/yyyy", event.value);
d1.setDate(d1.getDate()+5);
this.getField("Date2").value = util.printd("dd/mmm/yyyy", d1);}

Translate
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 ,
Nov 05, 2021 Nov 05, 2021

Note this adds 5 days, not 5 working days. Doing that will require a more complex solution, especially if you want to skip holidays, too.

Translate
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 ,
Nov 07, 2021 Nov 07, 2021

Hey @Nesa Nurani and @try67!

 

Thanks for the quick response. I think I may be putting Nesa's script in the wrong position and what happens is we're able to manually select a date on the second date field, but the +5 days condition isn't working.

 

The first date field is DATESUBMITTED_af

SpiralFoodsMarketing_0-1636348530948.png

 

While the current script is under DEADLINE

 

SpiralFoodsMarketing_2-1636348635323.png

Do you mean to say I should delete the current script as shown above, then paste your suggested script under "Run custom validation"?

 

Thank you!

 

Translate
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 ,
Nov 07, 2021 Nov 07, 2021

Change "Date2" to "DEADLINE" and use it in "Run custom validation" of "DATESUBMITTED_af" field.

As try67 mentioned it will add 5 days but not 5 working days.

Translate
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 ,
Nov 07, 2021 Nov 07, 2021
LATEST

Ah that works now, thank you! I was just wondering (because this is what we're trying to avoid), would it be possible to disable the selection of dates earlier than +5 of "DATESUBMITTED_af"?

 

Thanks again!

Translate
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