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: 10 Jul 2017 at 3:41am
Hi Everyone,

Thanks for the help, finally found a script that works:
var oDate = new Date();
console.println("DateField" + util.printd("dd/mm/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("DueDate" + util.printd("dd/mm/yyyy", oDate));
Back to Top
Sponsored Links


Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4108
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 30 Jun 2017 at 5:07pm
I would add the necessary code to compute the future date and set the due date field to your original function.

function date() {
     var oSysDate = new Date(); // get the systems date object;
      var oDateField = this.getField("DateField"); // get today's date field;
      if(oDateField.defaultValue == "")
      {
           oDateField.value = util.printd("dd mmmm yyyy", oSysDate); // fill with formatted date;
//           oDateField.defaultValue = oDateField.value; // set default value;
          var oDue = new Date();
          oDue.setDate(oDue.getDate() + 30);
           var oDueDate = this.getField("DueDate"); // get due date field object;
           oDueDate.value = util.printd("dd mmm yyyy", oDue); // fill in due date.
           oDueDate.defautlValue = oDueDate.value; // set value so it does not reset;
     } // end date field not set
} // end date function;

date(); // call my function;

You can also set the function to only update the date and due date if the default value of the date field is empty. This will prevent the field from being updated each time the form is entered and also stop the field from being reset if the form is reset.
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4108
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 30 Jun 2017 at 4:56pm
You only need to add the additional code for computing the due date and filling in the due date field to your function.

function date() {
     var oSysDate = new Date(); // get the systems date object;
      var oDateField = this.getField("DateField"); // get today's date field;
      if(oDateField.defaultValue == "")
      {
           oDateField.value = util.printd("dd mmmm yyyy", oSysDate); // fill with formatted date;
//           oDateField.defaultValue = oDateField.value; // set default value;
          var oDue = new Date();
          oDue.setDate(oDue.getDate() + 30);
           var oDueDate = this.getField("DueDate"); // get due date field object;
           oDueDate.value = util.printd("dd mmm yyyy", oDue); // fill in due date;
//           oDueDate.defautlValue = oDueDate.value; // set value so it does not reset;
     } // end date field not set
} // end date function;

date(); // call my function


Edited by gkaiseril - 30 Jun 2017 at 5:03pm
Back to Top
BAlheit View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 1112
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
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
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 629
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: 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
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
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4108
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
Merlin View Drop Down
Member
Member
Avatar

Joined: 03 Jun 2012
Location: 43.95 N / 4.82
Points: 46
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
BAlheit View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 1112
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
 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.063 seconds.