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

How to "count" number of attachments to .PDF and return total to form field?

New Here ,
Dec 03, 2020 Dec 03, 2020

I want to attach files to a PDF document using a "attach files" button (script works fine—all is well on this end).

 

Once files are attached, I would like a total of files attached to show in a form field on the PDF itself. So if there are two files attached, then the field reads "2". If there is one, then the field reads "1".

 

Thank you in advance!

TOPICS
Create PDFs , Edit and convert PDFs , PDF forms
1.1K
Translate
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 ,
Dec 03, 2020 Dec 03, 2020

Are you attaching the files as comments or as data objects?

Translate
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 ,
Aug 22, 2024 Aug 22, 2024

Hi, I have the same request 4 years later : )

Attachments are added via

this.importDataObject command.

Thank you in advance again!

Translate
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 ,
Aug 23, 2024 Aug 23, 2024

In that case you can use the dataObjects array to know how many attachments there are:

app.alert("There are " + (this.dataObjects==null ? 0 : this.dataObjects.length) + " attachments in this file.",3);

Translate
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 ,
Aug 30, 2024 Aug 30, 2024

Hey, I ended up not using it, but this was a helpful answer nonetheless! Thx!

Translate
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
New Here ,
Oct 02, 2024 Oct 02, 2024

Where do you put this to have the number show in a form field?  Validate?  Calculate?  Thanks in advance for your assistance.

Translate
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 ,
Oct 03, 2024 Oct 03, 2024
LATEST

In a calculation script, but be aware it won't update when a new attachment is added, as that doesn't trigger any field-related events. You can put it in a doc-level script (change event.value = ... to this.getField("").value = ... in that case) to update it when the file is opened, though.

Translate
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