My form has a button for users to attach a file. Clicking the button opens a browse window allowing the user to select the file and attach it to the form. Each time this is done the NumericField1 increases by one. This shows users how many attachments there are.
I am trying to find script that wil update the NumericField1 if the user deletes one of the attachments. I can get it to work with a button but cannot get the script to run during the layout:ready event. How can I get this to run if the user deletes an attachment using the trash can icon in the attachments pane? Here's my button script:
var oObj = event.target;
var fileAttachments = oObj.dataObjects;
if(fileAttachments != null)
Attachments.NumericField1.rawValue = fileAttachments.length;
Attachments.NumericField1.rawValue = "0";
I added a TestField (not connected to the database) and script to sed the same data that goes to the listbox now goes to the TextField. The TextField only displays the file path not the display text (file name). When saving, reopening and connecting to the database - the TextField is still populated.
So if you open the file, add some attachments, but do not connect to the DB if you close and open the file the list is still good? If that is correct then the assumption is that the DB connection is resetting that list box. I have run into this in the past. I had to change my Run-time options. Try it with Automatic or Manual to see if that works. Another option is to store your list items in a field and re-import them into the list after you connect to the DB assuming that also does not get reset
The script that populates the ListBox one file at a time is the click event of the button.
When a user wants to attach a file, they click the "Attach a File" button. The "Open" browse window appears, the selected file is attached, the NumericField1.rawValue increase by 1 and the ListBox display the file name.
Sorry for the late reply. I did not receive an e-mail telling me you posted again.
I have a button (click event) to populate the list box. I have used this script for years...
var d = new Date();
var myDoc = event.target;
var sFile = "myFile" + Math.floor(d/1000);
var myDataObject = myDoc.getDataObject(sFile);
var sFileName = myDataObject.path;
NumericField1.rawValue = NumericField1.rawValue + 1;
When I open the form, I receive two pop-up messages - first one connects to Table1 (if I answer Yes) and the second connects to Table2 (if I answer Yes). If I add an attachment, save the form, close and reopen - answer yes to connect to both database tables - the attachment listbox is blank. If I answer No not to connect to Table 1 and Yes to connect to Table 2 - the listbox still has the attachment listed and works correctly.
So if you are adding the names to a drop down list, when the user deletes an attachment it updates the drop down? if so you could count the entries in the drop down instead of the attachments. Now the question is why is the list box clearing? What event are you using to populate the list box?
Yes - it works when clicking the button but not on any of the events I've tried (Form Ready, Layout Ready, Doc Ready) I agree - it appears deleting an attachment from the attachment pane does not seem to trigger an event. I was using a ListBox to display the file names and when deleting the user selected the name from the list and clicked a button. That has worked great except this new form connects to a database. For some reason when adding an attachment, saving and closing the form, then reopening the form and letting it connect to the database, the ListBox clears (blank). I have been trying for days to figure this out!
The code is working for me, however I put it on a click event on a button to test. I am guessing that the problem is that the event is not triggering at the correct time. What event do you have it on? I tried it on Initialize, Form Ready and Layout Ready. My guess is that the action of adding/removing an attachment is not triggering an event.