Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Why not simply open the Attachments panel on the left and see which files are attached there?
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
The answer to do that question depends on what you want to trigger it. Should the field be updated each time the file is opened? If so, then placing it as a doc-level script is the right decision.
If the script is not working you should first open the JS Console and check if there are any error messages there.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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();