I am creating a form that allows users to save attachments to it. I searched the Discussion threads and found code that accomplished this. Under the click event of an "Add Attachment" button I have the following JavaScript code:
var myDoc = event.target;
var sFile = "myFile";
myDoc.importDataObject({cName: sFile});
var myDataObject = myDoc.getDataObject(sFile);
var sFileName = myDataObject.path;
attachments.attList.addItem(sFileName,sFile);
The code works fine and attaches files to the form perfectly. Added files are listed in a list box called 'attList' (in a subform called 'attachments'). I have also added working buttons that allow the user to open and remove attachements from the form. The issue is that, once the file is saved, closed, then re-opened the list box is no longer populated with the filenames of the attached documents. Is there a way to keep the list populated with the attachment filenames when the file is re-opened?
I have tried a number of ways to do this and the closest I have come to a solution is by having the form scan for attachments when opened and populating the list under the initialize command. I have been able to populate the list with the name of the last attached file with the following code:
var d=event.target.dataObjects;
for(var i=0;i<d.length;i++)
{
this.addItem(d[i].path);
}
but the "Open Attachment" button will not work, and only the name of the last attached file will appear in the list box. Any guidance is appreciated. Thank you.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
Can you check that in the File > Form Properties > Defaults tab the Preserve Script Changes is set to Automatic.
Niall
Views
Replies
Total Likes
Hi,
Can you check that in the File > Form Properties > Defaults tab the Preserve Script Changes is set to Automatic.
Niall
Views
Replies
Total Likes
Hey,
It was set to 'Manual'. I set it to 'Automatic' and removed the code from Initialize event of the List Box. Now it is working perfectly. Thank you very much for your assistance and quick reply.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies