Skip to main content
tlc27
Participating Frequently
February 15, 2017
Question

List box to show attachments

  • February 15, 2017
  • 4 replies
  • 3726 views

Hello all I found some wonderful scripts to enable users to add attachments to a PDF form. Unfortunately I cannot create a functioning list box that will show a list of attachments displayed in the attachments panel? I tried the code from a previous thread but it did not work. I am working in Adobe Acrobat XI not in LiveCycle.

Below is the script I tried to get the list box to work

// List ANY ATTACHMENTS

var d = event.target.dataObjects;

if (d != null)

for (var i = 0; i < d.length; i++)

{

console.println("Data object[" + i + "]=" + d.name);

}

Thanks

This topic has been closed for replies.

4 replies

tlc27
tlc27Author
Participating Frequently
February 16, 2017

I did a little bit more digging. I was able to find an example doc someone posted which has a button to attach files, lists the attached files in a listbox as comments/symbol and gives a count of the successfully attached files. It is not exactly what I was looking for but it will help a great deal. I have included a link to the example file if you would like to take a look. Thanks again for your help.

https://files.acrobat.com/a/preview/12abdfeb-b387-4a4d-8e50-c24bf3e018ea

NKOWA555
Inspiring
February 16, 2017

You could add a document javascript like so:

function refreshAttachments()

{

//var d = event.target.dataObjects;

// "listAttachments" = listbox field name

var lst = this.getField("listAttachments");

lst.clearItems();

var d = this.dataObjects;

if (d != null)

for (var i = 0; i < d.length; i++)

{

console.println("Data object[" + i + "]=" + d.name);

lst.insertItemAt("[" + i + "] " + d.name,d.name,i);

}

}

refreshAttachments();

tlc27
tlc27Author
Participating Frequently
February 16, 2017

Was able to open JS Console script seems to be working fine no errors. I would like the filed to update whenever a new attachment is added.

try67
Community Expert
Community Expert
February 16, 2017

That's not possible, I'm afraid, as that event doesn't have any triggers attached to it that could be used to execute the script.

tlc27
tlc27Author
Participating Frequently
February 16, 2017

I have a button that does that but since I am trying to learn more about scripting in Adobe I wanted the form to behave more like a traditional form that shows the attachments listed under the button.

try67
Community Expert
Community Expert
February 16, 2017

You can do it using this code:

var f = this.getField("AttachmentsList");

f.clearItems();

var d = this.dataObjects;

if (d != null) {

    var names = [];

    for (var i = 0; i < d.length; i++) {

        names.push(d.name);

    }

    if (items.length>=0)

        f.setItems(names);

}

tlc27
tlc27Author
Participating Frequently
February 16, 2017

Hi try67 thank you for your help. Because I am new to scripting I added this to the Javascript for a list box that I named AttachmentsList, Select Trigger - Mouse Up, Select Action - Run a Javascript and added the code you provided. Unfortunately this didn't work, so I added it to the Document's Javascript this also didn't work. AM I placing the code in the wrong place?

try67
Community Expert
Community Expert
February 15, 2017

Why not simply open the Attachments panel on the left and see which files are attached there?

Participant
September 21, 2022

Why answer a question with a question? Clearly they dont want to do it that way... or they wouldn't have asked! I can think of several reasons a developer wouldn't want to rely on a end user to figure out how to open an attachmet pane when it could "simply" (as you put it) be displayed automatically and within the document. Golly I hope you're not the "Community Expert" on any other posts!