12 Replies Latest reply on Feb 22, 2017 11:52 AM by Karl Heinz Kremer

    autogenerate date time seconds in form field

    daviscott1982

      Ok, so this is my first time asking a question on here.  I am new to Acrobat, and creating Forms, with very, very entry level javascripts.  Here is what I am trying to do:

       

      1. I have created a "quote document" that we will be using on a mobile platform.

      2. Originally, I created a text field that automatically updated the number of the "Quote Number" field by 1 everytime it was opened. 

      3. However, it updates only when the document is saved as the same name as the original file.  So I deleted this. 

      4. A workaround for this I believe would be to autogenerate a number in a field, in my case the field name is "Quote Number".  The number should read:

      4 digits yr, 2 digit month, 2 digit date, time and seconds.  There has to be a common request for this? Again, If you could provide some basic instructions on how to insert this into my document as well it would be appreciated. 

      5. When the document is opened, this number would generate. However, once the document is opened, the number would not be editable. 

       

      Thanks for your help in advance!

        • 1. Re: autogenerate date time seconds in form field
          Joel_Geraci Adobe Community Professional

          For "time and seconds" I assume you want hours, minutes, seconds all 2 digits each and hours in military time. Correct?

           

          Also, that's not a great way to create a unique number unless you're the only one using the form. We can certainly help you create the script but you may want to rethink your solution.

          • 2. Re: autogenerate date time seconds in form field
            Karl Heinz Kremer Adobe Community Professional

            As Joel indicated, doing this with just a timestamp is not the best way to come up with a unique ID. You would have to at least add some information about the computer and the user ID to have a chance of a unique ID. The best way is to do this on a server and have the client (the form open in e.g. Adobe Acrobat or the free Adobe Reader) request a new "form number" from the server. Take a look here for a solution that would work with Adobe Acrobat: Getting a Serial Number Into a Form Using SOAP - KHKonsulting LLC

             

            If you also want to support the free Reader, SOAP does not work, but you could get the number from the server via FDF/XFDF. 

            • 3. Re: autogenerate date time seconds in form field
              Joel_Geraci Adobe Community Professional

              Mobile will be problematic with any server based solution. Unless you're opening from the Document Cloud, an Adobe viewer won't be the first thing that gets a hold of the PDF on iOS. The server connection will get lost when "Open In" is selected to fill the form in Adobe Reader on mobile, I don't think it handles FDF or XFDF either... though I haven't tried in a while. Additionally, the Reader on Mobile JavaScript API doesn't have the identity object to get a user ID or any other information about the device other than the platform.

              • 4. Re: autogenerate date time seconds in form field
                daviscott1982 Level 1

                Well, let me start off by saying thanks to all of you for your quick support. 

                 

                Because this document will only be utilized by a couple of individuals, having a "unique" ID generated by using the year, month, day, while including the time (including seconds to minimize chance of duplicity) will be sufficient.  I would prefer the following format:

                 

                Year - 2 digit

                Month - 2 digit

                Day - 2 digit

                Time - Here I think seconds would be all that is needed.  I do not necessarily need the hours and minutes. 

                 

                And, furthermore, I would think that Milliseconds would further minimize the chance of duplicity?  a couple users will be using this in the field, so the server-side application will not be available.

                • 5. Re: autogenerate date time seconds in form field
                  daviscott1982 Level 1

                  Thanks for your response.  I replied to the group in the main string.

                  • 6. Re: autogenerate date time seconds in form field
                    daviscott1982 Level 1

                    Joel,

                    Thanks for the information.  Here is my response to yours:

                     

                    Because this document will only be utilized by a couple of individuals, having a "unique" ID generated by using the year, month, day, while including the time (including seconds to minimize chance of duplicity) will be sufficient.  I would prefer the following format:

                     

                    Year - 2 digit

                    Month - 2 digit

                    Day - 2 digit

                    Time - Here I think seconds would be all that is needed.  I do not necessarily need the hours and minutes.

                     

                    And, furthermore, I would think that Milliseconds would further minimize the chance of duplicity?  a couple users will be using this in the field, so the server-side application will not be available.

                    • 7. Re: autogenerate date time seconds in form field
                      Joel_Geraci Adobe Community Professional

                      Ok - so... milliseconds since midnight of the current date then?

                      • 8. Re: autogenerate date time seconds in form field
                        daviscott1982 Level 1

                        That would be ideal, yes.  Could you also assist if i wanted to actually include hours and minutes as well as milliseconds?

                        • 9. Re: autogenerate date time seconds in form field
                          gkaiseril MVP & Adobe Community Professional

                          That will be custom JavaScripting using the JavaScript Date object and methods and then using Acrobat's util.printd or util.printf method.

                           

                          This can be problematic with mobile devices since none or very few allow use of or support the document level script.

                           

                          Another issue will be, once assigned a value do you want to keep the value? Mobile devices might not support the defaultvalue property

                           

                          Assuming a non-mobile device one could have a document level script like:

                           

                          function Initialize()

                          {

                          // only add seauence number if defaultValue of the field is empty;

                          var bReturn = true;

                          var oSeq = this.getField("Sequence");

                          if(oSeq == null) {

                            app.alert("Sequence field error");

                            bReturn = false;

                          }

                          if(oSeq.defaultValue == "")

                          {

                            // get current Date object;

                            var oDate = new Date();

                            oSeq.defaultValue = util.printd("yymmddss", oDate);

                            oSeq.value = oSeq.defaultValue;

                            bReturn = true;

                          }

                          return bReturn;

                          } // end Initialize funciton definition;

                          Initialize(); // initialize the form;

                           

                          It is easier to clear the dafaultValue and using it also allows resetting of the form without losing the sequence number.

                          • 10. Re: autogenerate date time seconds in form field
                            daviscott1982 Level 1

                            I entered this into the page properties to process when the document is opened.  However, after the first time opening it, i could not get it to work again.  Also, to Joel's credit, i see that the milliseconds could repeat, therefore i will also need to include HH and MM into this number to appropriately keep it organized by date. 

                            • 11. Re: autogenerate date time seconds in form field
                              daviscott1982 Level 1

                              Nevermind. i notice you referenced the default value.  When i clear that, it issues a new number.  However, after second thought, i do want the hours and minutes, along a abbreviated month (Feb for example) instead of "02"

                              • 12. Re: autogenerate date time seconds in form field
                                Karl Heinz Kremer Adobe Community Professional

                                Good call on the defaultValue - I was just about to write about that.

                                 

                                Take a look at this line:

                                  oSeq.defaultValue = util.printd("yymmddss", oDate);

                                 

                                The format string is what makes up the final "sequence" code. You can change things on your own - as long as you know what the different format options are. You can look these up here: Acrobat DC SDK Documentation - util.printd()

                                1 person found this helpful