Skip to main content
Participating Frequently
June 23, 2020
Answered

Javascript help for unique document ID field

  • June 23, 2020
  • 3 replies
  • 2743 views

I am very new to creating Adobe Forms and also very new to Javascript. I've been tasked at work to create a form with fillable fields that can be submitted whenever someone needs to request a new project from my department. Easily done.

 

The catch is that they also wanted 1) the ability to add attachments to each submission (Solved), and 2) the ability to create a unique document ID each time a submission comes in. #2 is where I'm stuck!

 

I did some digging through the forums and found some different javascript codes that did the trick. After experimenting, I found that the yyyymmddHHMM format works perfectly for assigning document IDs. I set the script to assign a number when the Form is opened. Everything workedgreat! ...until I "Distribute" the Form and publish it.

 

In short, even though I clear the fields and save the document, the Form "opens" anew and assigns a document ID in the text field when I hit Distribute to publish the Form, which makes the document ID static/permanent for anyone using that distributed form.

 

Any ideas on how to work around this issue?

 

Here is the code I tried using (not sure what most of this actually means):

 

 

function DocID()
{
}

var f = this.getField("DocID");
if (f.valueAsString=="") f.value = util.printd("yyyymmddHHMM", new Date());

 

 

 

This topic has been closed for replies.
Correct answer Thom Parker

this.getField("NAME").value = this.docID;


this.getField("NAME").value = this.docID[0];

 

It's an array of 2 ID's Document and Instance.

3 replies

JR Boulay
Community Expert
Community Expert
June 26, 2020

"2) the ability to create a unique document ID each time a submission comes in."

Are you aware that any PDF file already embed a "Document ID" which is unique and updated each time the file is saved?

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/Acro12_MasterBook/JS_API_AcroJS/Doc_properties.htm?rhhlterm=docid&rhsyns=%20#XREF_34893_docID

Acrobate du PDF, InDesigner et Photoshopographe
PoccaEngAuthor
Participating Frequently
June 26, 2020

I was not aware, but this is useful to know. For future reference, how would I use this in a javascript text field to show it?

Thom Parker
Community Expert
Community Expert
June 26, 2020

I actually covered this in my first post.

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
June 25, 2020

I think that Bernd is asking you to share the form so we can look at it.  The fact is that your post does not contain enough information for us to provide any help.  

 

However, as it happens, all PDF Documents contain a 2 part ID.  The first part never changes, so you can always identify the specific document, it's the document ID. And the second part only changes when the document is saved with changes, it's the instance ID.  

 

You can leverage these IDs to your process, or stay with the date/time ID. 

 

One of the problems with ID's is figuring out exactly when the ID is generated, and how it is locked down. With the Instance ID, the ID is set when the user fills out the form, and it doesn't change as long as the form is not modified.  

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
PoccaEngAuthor
Participating Frequently
June 25, 2020

Thank you for the help, and I apologize for misunderstanding. I've attached the form to the original post.

 

Some more information, just to be a bit clearer: The DocID field is at the very bottom left, where I wanted it to be unassuming. I want it to populate only when the user opens the document to fill it in/submit it. I am using Adobe DC and trying to use the Distribute Form function.

Thom Parker
Community Expert
Community Expert
June 25, 2020

The ID code on the form is somewhat self defeating. It fills and locks the value anytime the form is opened. You would need to clear the DocID field imediately before sending it out. And I'm not sure that would work. The best strategy is to have a definate trigger that you can control.  For example, put a button on the form that when pressed resets all the fields and sets the ID. So you know the user is starting fresh. You could force the issue by locking the fields up front. The pressing the button unlocks them. A nice variation on this theme is to use the lite security scheme described here:

https://www.pdfscripting.com/public/Lite-Document-Security-Description.cfm

 

This method guarentees that the user is filling out the form on a desktop Acrobat or Reader, so there is no issue with 3rd party tools that do not respect the Form Tracking protocal. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
June 24, 2020

Put the form on a server and share the link.

PoccaEngAuthor
Participating Frequently
June 25, 2020

The Document ID still freezes at the time the Distribute function is used, no matter if emailed, put on a Sharepoint site, or put on a local server. (We want to use the Distribute function because of its tracking capabilities.)

Bernd Alheit
Community Expert
Community Expert
June 26, 2020

How does you distribute the document?