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

dates do not work

Community Beginner ,
Feb 05, 2018 Feb 05, 2018

In my Adobe Acrobat Pro DC.

I don't have the date and image icons, but with a script i was able to make date work in a couple of my forms but, when i tried to do the same in another form it would not work. I went back one of the other forms that was working, and they are not working any more.

TOPICS
PDF forms
1.5K
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
1 ACCEPTED SOLUTION
Community Beginner ,
Feb 06, 2018 Feb 06, 2018
LATEST

Thank you, its working now.

View solution in original post

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
LEGEND ,
Feb 05, 2018 Feb 05, 2018

Since a special custom script needs to be added to the form and that script requires some additional form fields and code to work, it is pretty hard to find an error without seeing all the code and a sample of the form.

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 ,
Feb 05, 2018 Feb 05, 2018

Please explain more, What do you mean by make date work? and what do icons have to do with this?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Feb 05, 2018 Feb 05, 2018

Hello Thom,

I am creating a form that each day I open it, “today’s date” will appear; then I would like it to post a date 45 days later such as “Expiration Date”

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 ,
Feb 05, 2018 Feb 05, 2018

And you have scripts for this? and they worked at one time?

Please post the scripts and indicate the location of each script within the PDF.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Feb 05, 2018 Feb 05, 2018

Today’s date:

(function () {

    var sDate = getField("OriginalDate").valueAsString;

        var d = util.scand("mm/dd/yyyy", sDate);

        var days = getField("DaysAdded").value;

        d.setDate(d.getDate() + days);

        if (sDate) {

        event.value = util.printd("mm/dd/yyyy", d);

    } else {

        event.value = "";

    }

})();

Today’s date plus 45:

(function () {

    var sDate = getField("OriginalDate").valueAsString;

  var d = util.scand("mm/dd/yyyy", sDate);

    var days = getField("DaysAdded").value;

    d.setDate(d.getDate() + 45);

    if (sDate) {

        event.value = util.printd("mm/dd/yyyy", d);

    } else {

        event.value = "";

    }

})();

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
LEGEND ,
Feb 05, 2018 Feb 05, 2018

We also need to know the action where you placed the code. It looks like it would be the field calculation actionl. You need to enter a valid date string into the field "Original Date" for the calculations to be performed.

If you want the current date to appear in the "Original Date" field automatically, then you need to add a document level script like:

this.getField("OriginalDate").value = util.printd("mm/dd/yyyy", new Date());

It looks like you just cut and pasted someone else's code with any thought.

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 ,
Feb 05, 2018 Feb 05, 2018

I am new and don’t know how to do the codes, I have copied them from the forum. Here is the part of the form where I need the dates.

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 ,
Feb 05, 2018 Feb 05, 2018

Both scripts you posted are nearly identical. Neither one gets today's date.

What they do is get a date string from a field named "OriginalDate" and add days to it from another field named "DaysAdded".

if either of these fields was missing from the form, then the scripts would fail. This seems like the most likely reason the script stopped working.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Feb 05, 2018 Feb 05, 2018

What scripts would I use?

Regards,

Jim Vogel

Office: +1 (317) 770-6315

INDEX Corporation

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 ,
Feb 05, 2018 Feb 05, 2018

GKaiseril already gave you the script for getting the current date when the document is opened.

Add this code to the same script, it adds 45 days to the current date. Change "Expiration Date" to the name of your field that is suppose to contain today's date + 45 days.

var d = new Date;       

d.setDate(d.getDate() + 45);

this.getField("Expiration Date").value = util.printd("mm/dd/yyyy", d);

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Feb 06, 2018 Feb 06, 2018
LATEST

Thank you, its working now.

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
LEGEND ,
Feb 05, 2018 Feb 05, 2018

I would start with just getting today's date to populate a field upon opening the PDF. Then work on adding 15 days to the date.

This is a public and very open forum, you should not be publishing personal information in your posts.

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