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;
}
else
{
Attachments.NumericField1.rawValue = "0";
}
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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!
Views
Replies
Total Likes
Additional Note: the ListBox was not connected to the database.
Views
Replies
Total Likes
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?
Views
Replies
Total Likes
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);
myDoc.importDataObject({cName: sFile});
var myDataObject = myDoc.getDataObject(sFile);
var sFileName = myDataObject.path;
ListBox1.addItem(sFileName,sFile);
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.
Views
Replies
Total Likes
Which Event is your script to populate the list on? I am suspecting that when DB connection is made the event is being overridden. I would look at other options and see if that solves the problem
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
I appreciate your help.
I tried switching from Automatic to Manual but the problem still exists.
Can you help me with the script to save the list items in a field and re-import them?
Views
Replies
Total Likes
I would be happy to try. Can you send me your file?
Views
Replies
Total Likes
sorry mousland@gmail.com
Views
Replies
Total Likes
Additional information:
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
you have to use formattedValue instead of rawValue to get the file name.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies