• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript help for unique document ID field

Community Beginner ,
Jun 23, 2020 Jun 23, 2020

Copy link to clipboard

Copied

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());

 

 

 

TOPICS
Acrobat SDK and JavaScript

Views

1.2K

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

correct answers 3 Correct answers

Community Expert , Jun 25, 2020 Jun 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 bu

...

Votes

Translate

Translate
Community Expert , Jun 28, 2020 Jun 28, 2020

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

Votes

Translate

Translate
Community Expert , Jun 28, 2020 Jun 28, 2020

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

 

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

Votes

Translate

Translate
Community Expert ,
Jun 23, 2020 Jun 23, 2020

Copy link to clipboard

Copied

Put the form on a server and share the link.

Votes

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
Community Beginner ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

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.)

Votes

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
Community Expert ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

How does you distribute the document?

Votes

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
Community Beginner ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

I'm using the "Distribute" function under "Prepare Form" tools (no preference on email vs internal server). We want to be able to track it, and this is our first time testing this function.

Votes

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
Community Expert ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
Community Beginner ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

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.

Votes

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
Community Expert ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
Community Beginner ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

Thanks for the tips! I will try this option and see how it works out for our staff.

Votes

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
Community Expert ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

"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/Do...

Votes

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
Community Beginner ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

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?

Votes

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
Community Expert ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

I actually covered this in my first post.

 

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

Votes

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
Community Expert ,
Jun 28, 2020 Jun 28, 2020

Copy link to clipboard

Copied

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

Votes

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
Community Expert ,
Jun 28, 2020 Jun 28, 2020

Copy link to clipboard

Copied

LATEST

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

 

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

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

Votes

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