Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Automatically Setting the Due Date in an Invoice
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Automatically Setting the Due Date in an Invoice

 Post Reply Post Reply Page  12>
Author
Andy63 View Drop Down
New Member
New Member
Avatar

Joined: 27 Jun 2017
Points: 8
Post Options Post Options   Quote Andy63 Quote  Post ReplyReply Direct Link To This Post Topic: Automatically Setting the Due Date in an Invoice
    Posted: 27 Jun 2017 at 3:30am
OK Here is what I want.
1) I’m creating an invoice, with a text field (DateField) that will display the current date as soon as you open the form. I have customized the format as dd/mm/yyyy, and used the following document javascript to do this:
function date() {
 var fld = this.getField("DateField");
 fld.value = util.printd("dd mmmm yyyy",new Date());
}
date(); // call my function

2) What I want to do next is to add a second text field (DueDate), where the current date is advanced by 30 days, and this date is displayed in this text field in dd/mm/yyyy format, also as soon as you open the form.

I have tried a couple of JS options, none of which have seemed to work – no doubt in large part due to my ignorance of JS.

Is there a way to do this?
Back to Top
Sponsored Links


Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4076
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 27 Jun 2017 at 8:59pm
Have you used Google to search for any JavaScripts to adjust the date object?

There are any number of tutorials about this. Some will show how to adjust the date using the number of milliseconds other tutorials will show how to use the getDate and setDate methods to adjust the date.

Both the following scripts will compute the date 30 days from now.

// using getDate/setDate;
var oDate = new Date();
console.println("The date is " + util.printd("mm/dd/yyyy", oDate));
// get the date of the month;
var nDate = oDate.getDate();
// add 30 days;
nDate += 30;
// set the date;
oDate.setDate(nDate);
console.println("In 30 days it will be " + util.printd("mm/dd/yyyy", oDate));

// using getTime and new Date;
var oDate = new Date();
console.println("The date is " + util.printd("mm/dd/yyyy", oDate));
// get the time in milliseconds since the Epoch date;
var nDate = oDate.getTime();
// milliseconds in one day;
var nOneDay = 24 * 60 * 60 * 1000;
// add 30 days in milliseconds;
nDate += 30 * nOneDay;
// create new date object;
var oNewDate = new Date(nDate);
console.pritnln("In 30 days it will be " + util.printd("mm/dd/yyyy", oNewDate));
Back to Top
Andy63 View Drop Down
New Member
New Member
Avatar

Joined: 27 Jun 2017
Points: 8
Post Options Post Options   Quote Andy63 Quote  Post ReplyReply Direct Link To This Post Posted: 28 Jun 2017 at 7:39am
OK, this is puzzling...

The script works on the Javascript console, but no date displays in the text field.

Yeah, did try a few other pages and tutorials, but honestly got lost in it all.
Back to Top
BAlheit View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 1097
Post Options Post Options   Quote BAlheit Quote  Post ReplyReply Direct Link To This Post Posted: 28 Jun 2017 at 8:20am
You must set the value in the field.
Back to Top
Merlin View Drop Down
New Member
New Member
Avatar

Joined: 03 Jun 2012
Location: 43.95 N / 4.82
Points: 39
Post Options Post Options   Quote Merlin Quote  Post ReplyReply Direct Link To This Post Posted: 28 Jun 2017 at 3:28pm
You must absolutely read this article "The practicalPDF Date Library for Adobe Acrobat":
http://practicalpdf.com/the-practicalpdf-date-library-for-adobe-acrobat/
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4076
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 28 Jun 2017 at 4:32pm
Did you open the JavaScript console?
Back to Top
Andy63 View Drop Down
New Member
New Member
Avatar

Joined: 27 Jun 2017
Points: 8
Post Options Post Options   Quote Andy63 Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jun 2017 at 3:11am
Hello Again,
Firstly, apologies for being such an ignoramus with all this.

Hi Merlin
Yes I have tried reading a couple of articles online, but have generally come away more confused.

Hi gkaiseril
Yes I did open the javascript console, and the script itself works fine. What I can't get it to do is display the due date in the 'Due Date' text field.

Hi BAIheit
Sorry, I'm not sure what is mean by 'you must set the value in the field'.

Again, apologies for the rookie questions. Help is much appreciated.
Back to Top
Andy63 View Drop Down
New Member
New Member
Avatar

Joined: 27 Jun 2017
Points: 8
Post Options Post Options   Quote Andy63 Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jun 2017 at 3:12am
Just another question...

Should this be a document-level script, or a custom calculation script?

I have tried both approaches, but neither one seems to work.
Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 617
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jun 2017 at 11:08pm
If you want the code to run when the file is opened it needs to be placed as a doc-level field.
But first get it working... Run it from the Console and see what the results are.

By the way, if the field's format is "dd/mm/yyyy", why are you using a different format pattern string ("dd mmmm yyyy") in your code?
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
Andy63 View Drop Down
New Member
New Member
Avatar

Joined: 27 Jun 2017
Points: 8
Post Options Post Options   Quote Andy63 Quote  Post ReplyReply Direct Link To This Post Posted: 30 Jun 2017 at 8:25am
Hi try67,

Yes, I have run it in the JS console - and it seems to have no problem setting the due date in that, but nothing displays in the 'Due Date' field (DueDate)

You're right about the format, I've adjusted it, but it has still made no difference.
Back to Top
BAlheit View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 1097
Post Options Post Options   Quote BAlheit Quote  Post ReplyReply Direct Link To This Post Posted: 30 Jun 2017 at 4:10pm
What is the name of the field?
Back to Top
 Post Reply Post Reply Page  12>
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.031 seconds.