Auto Populate Calendar (with cut-off date)

New Here ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

Hi all!

I figured out the crossed-off issue (field calculation order), but still have one I'd like to tackle. Once I designate my "1" on my calendar, all the numbers fill in beautifully, but I need it to stop on a certain number without filling in extra spaces (i.e., August ends on the 31st, so I'd need the numbers to stop at 31).

Any help you can give is greatly appreciated! Keep in mind, I'm 100% new to this! It's all Greek to me.

Thank you for your time!

Leah

I found what I thought to be the solution I needed in a thread from years ago. I have a blank calendar template that I'd like to push out onto my iPad without having to manually fill it in each year (I'm a teacher and hate purchasing calendar/planners each year as well as the legwork I've been doing by manually filling in my own digital ones). The issue I'm having is that the following script works for the first two numbers, then the string stops. I checked to make sure everything was named correctly and that the custom calculation script follows the previous name (i.e. if the label is "Aug_2", the script reads "Aug_1"; label "Aug_3", script "Aug_2"; etc.)

Here's what I found previously in the forums:

if (this.getField("Aug_1").valueAsString!="") event.value = Number(this.getField("Aug_1").valueAsString)+1;

When I, for example, choose any box and fill in "1" the next box successfully fills with "2," but that's where it ends. I'd love if it would just continually fill the numbers in without any fiddling.

Message was edited by: Leah Dawdy

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

191

Likes

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
Most Valuable Participant ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

Please provide some more details about what you're trying to achieve and how you've set it up so far.
Are you using a script to populate the fields? If so, please post the code.

Likes

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
New Here ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

Sorry about that! I'm a teacher and tired of manually filling in my digital block plans and calendars (also tired of buying them each year). I found this script to populate the fields:

if (this.getField("Aug_1").valueAsString!="") event.value = Number(this.getField("Aug_1").valueAsString)+1;

It works beautifully to fill in the calendar dates. What I need to do now is add to the script to get it to stop at, say, 31 for the month of August.

Likes

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
Most Valuable Participant ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

Are you filling it one month at a time? If you only have 31 fields for August, then why is this a problem? Also, not quite sure why you need to use a script for this in the first place... Isn't the value of "Aug_1" always going to be "1", and of "Aug_2" always "2", etc.?

Likes

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
New Here ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

The issue is that each month doesn't begin on the same weekday each year. I have the weekdays at the top of the calendar, like one you'd buy in the store, and each month I'd like to type "1" in the square for the day the month begins and have it autofill the rest. That way, if it begins on the first Monday, it autofills the numbers. But if it begins on the first Saturday, it'll autofill the correct sequence, too, without me having to move the text boxes around.

The issue I'm having in doing it this way for a month that begins early in the first week is that those autofilled numbers extend beyond 31.

Likes

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
Adobe Community Professional ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

You have an easy solutions for handling calendar issues. There is a JavaScript Date Object that will provide you with all the information you need.  All you have to do is lookup the functions and properties of this object to figure out anything you want to know about dates.

Here's the Core JavaScript reference entry for the date object:

Date - JavaScript | MDN 

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

Likes

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
New Here ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

I'm not sure exactly what I'm looking at, but from reading and trying some of the ones that sounded like it could be what I needed, I didn't find what I'm looking for.

What I have is effectively one of these:

download.png

And what I want to do is fill those little date boxes with a numeral corresponding to when the month begins, letting everything else fill in once that one's filled in. So I also need it to stop on a certain number. It doesn't seem like these scripts will automatically know that Sunday through Friday is at the top of the calendar, and to intuitively fill in the squares based on the day of the week, the month, and the year. Correct me if I'm wrong, but I didn't see one that could do this.

If I completely missed that script, then that's on me and my new-ness to all this and I deeply apologize. And if it's easier to point me in the right direction for a way to set it up so it counts the boxes and stops on a specific number, that's fine, too!

Likes

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
Most Valuable Participant ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

I think you should approach it the other way around. You create a Date object (using the Date object constructor method or the scand method of the util object) and set it to the desired date (for example, August 1st 2019). Now you use the getDay method of this object to find out which day of the week it is, and start populating the rest of the fields from there. So your field names should not be Aug_1, Aug_2, etc., but Aug_Sunday1, Aug_Monday1, etc. (1 being the number of the row).

Likes

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
New Here ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

I see! Okay, so I created the Date object and set it to the desired date. Is there a way to get the rest of the Date objects to populate automatically, once the first is set? I've changed them all to be Date objects labeled like you suggested.

Likes

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
Most Valuable Participant ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

The Date objects only exist inside your code, they are not preset on the actual form.

I'm revising my advice to name the fields like this:

Aug_1_1 (first Monday in the first week of August), Aug_1_2 (first Tuesday in the first week of August), etc.

Once you have your Date object you need to locate the field that matches it. Let's take the example above, Aug 1 2019 is Thursday, which you can know by accessing the getDay method.

So we have:

var august1st = util.scand("mm/dd/yyyy", "08/01/2019");

var augst1stDay = august1st.getDay();

augst1stDay equals 4 (ie, Thursday)

So we start populating the fields from Aug_1_3 (which is "1"), and then we increment the august1st date by 1 day, until September 1st, and at the same time we populate the fields start from Aug_1_4 to Aug_5_6 (the last day of the month, August 31 2019 is a Saturday on the fifth week).

There are additional complications for this, though. This is not a simple scripting task...

Likes

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
Adobe Community Professional ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

So it doesn't sound like you are familiar with programming. What you are asking for is a somewhat complex piece of code that requires more skill with programming concepts than actual knowledge of JavaScript or Acrobat. You would be well served to either hire a programmer or spend some time learning programming concepts.

Just to give you and idea, there are a couple of parts to this process. The first bit is the field names on your calendar. The convention used to name the fields guides much of the code development. You have to decide on this first. 

The next bit is the technique for generating the dates to be placed in the fields. The general idea we're starting with is that you have the year and month for the particular calendar section. One way to do this is to create the date object for the first day of that month and year. Then extract the weekday on which it starts. There's a date object function for this. Then all you have to do is fill in the fields starting on that weekday. How you actually do that (the order of the operations) depends on how the fields are named. TaDa, Done!!

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

Likes

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
New Here ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

LATEST

Thom & try67,

Thank you both so much for all your patience. I didn't foresee this being such a tricky thing, but I really appreciate all your help and advice! I hope to learn enough to be able to do something like this on my own, but you've been very helpful explaining it all!

Likes

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