"However, when I close "Form-Mobile.fp7" and then re-open it a few minutes later, the new record is there" - I can't believe that, so I think that's where the solution will lie. My guess is that the script is opening one file and you are double-clicking another file (with the same name). The file you are double-clicking is, of course, the correct file which is why you always see the record you expect.
You could test that theory by changing your import script to give you a dialogue at the Import Records script step, at the Specify File... step. Then manually navigate to where the real file is (desktop, I think you said) and see if the script then performs correctly every time.
If that is the case then you could have a look in 'Manage data sources' and see the list that is there. It could be that your file is looking for the file being open and if it finds it already open it imports from it. If not, it moves down the list of data sources until it finds one, and it may be finding a file with the correct name, but in the wrong location, before it gets to the correct one.
Just a hunch.
Thanks for the input, but what you suggested is not the case. I only have one external data source for either file and I only keep "Form-Database.fp7" open at all times and never open "Form-Mobile.fp7" or any other Filemaker file.
And I tried adding Flush Cache to Disk to the beginning of the script but that did not solve the problem. But here is what I noticed.
I keep the "Form-Database.fp7" file open at all times on the iMac. I just drop the "Form-Mobile.fp7" from the iPad to the desktop and then run my script from "Form-Database.fp7". I do not ever open "Form-Mobile.fp7". When I do it this way, there is a 50/50 chance that "Form-Mobile.fp7" will update and my script will work. Last time around, it worked. This time around, it did not. (I collect data and sync once an hour).
This past time, after my script didn't work, I opened up "Form-Mobile.fp7" on the iMac and sure enough the new record was not showing. I then closed "Form-Mobile.fp7" and then also closed "Form-Database.fp7" and then reopened "Form-Mobile.fp7" and the new record was there. So it could have been that closing "Form-Database.fp7" allowed it to do whatever and update or it could be that just closing and reopening "Form-Mobile.fp7" is what fixed it.
I am going to see if I can add to the script to close and open the files in different fashions to test multiple theories and I'll see how it goes during the next few syncs.
Could you clarify if you meant to distinguish:
First post: "on the iMac and sure enough, the new record isn't there"
Previous post: "on the iMac and sure enough the new record was not showing"
When you open the file and it 'isn't there', and then it 'is there', is there a difference in the total record count?
Yes. The record count is one higher.
After my script doesn't work, I open the file and see 797 records and the latest record isn't there. I close the file and reopen it and now there are 798 records and my latest record is there.
I have confirmed that closing and reopening "Form-Mobile.fp7" on the iMac will not cause the new record to show up. If I close "Form-Database.fp7" and then reopen "Form-Mobile.fp7", the record count updates properly.
So is it possible that "Form-Database.fp7" could still be using "Form-Mobile.fp7" after the first sync and that is why the file isn't properly updating when I come around to sync again... because "Form-Mobile.fp7" is still being accessed.... but if this is the case, it is kind of weird that the file is technically overwritten... just for some reason record count does not update until I close "Form-Database.fp7". Kinda weird... I am gonna tinker with it some more and report my findings.
Thanks for the help thus far.
Okay so I have some more findings.
It turns out there are two separate problems going on here.
Problem #1 - Solved: It seems Filemaker likes to keep data in a memory cache for a while before writing that data to disk. This was causing problems with the file not being up to date when copying from iPad to iMac. I solved this by adding a "Flush Cache to Disk" command to a script that I run before connecting the iPad to the iMac. This way, the data gets written to disk and always the up to date file comes off the iPad.
Problem #2 - Unsolved: This is where I am stuck. Remember, I keep "Form-Database.fp7" open on the iMac at all times. Let's say in this scenario, I just booted up the iMac and opened "Form-Database.fp7" and have opened nothing else. I go and collect data on the iPad and then copy "Form-Mobile.fp7" to the iMac. I run the import script in "Form-Database.fp7" (which I have now just stripped down to run the import command, Show All Records, Go to Last) and it works perfectly.
Leaving "Form-Database.fp7" open on the iMac, I go and collect more data with the iPad. I come back and copy "Form-Mobile.fp7" onto the iMac. This time when I run the import script from "Form-Database.fp7" the record count does not increase. Nothing is imported. At this point, if I click "Form-Mobile.fp7" on the desktop of the iMac, it appears as though the new record is not there. I can close and reopen it as many times as I'd like, the new record is not there. Now if I close "Form-Database.fp7" at this point, and then open up "Form-Mobile.fp7" the new record is there. Record count has increased and now I can open up "Form-Database.fp7" again and run the import script and it works perfectly.
To make a long story short, every time I copy my updated mobile file from the iPad, I have to close/reopen my database file or else the import script won't import anything because the Mobile file won't update unless I do that. I am going to have other Users using this and I really don't want then closing/reopening the database.
Is this a bug or something? I am going to try one more thing I just thought of right now and then if that doesn't work, make sure everything is up to date as I remember seeing something asking me if I wanted to update Filemaker or something. I use FM11 btw.
I worked around problem #2 above by doing the following:
I created a blank database called "helper.fp7."
In this database, I created the following script called Close and Reopen Database:
Close File ["Form-Database.fp7"]
Open File ["Form-Database.fp7"]
Then I added to the end of my import script in "Form-Database.fp7"
Perform Script ["Close and Reopen Database" from file: "helper.fp7"
This closes kills whatever is going on between "Form-Database" and "Form-Mobile" and uses an unrelated source to reopen the database. I tried using this method before, but I used "Form-Mobile" as the carrier for the Close and Reopen Script. That didn't work because it still created a connection between the two which ends up not being terminated.
So far I have successfully completed 8 imports in a row without having to manually close/open my database. So yayyy!!! My problems are solved. =D
I have to say that I am worried about you method of finding the record(s) to import. It seems to be a tocuh precarious. For example, will you guarantee that all users, (including yourself) will absolutely always sync back to the central file after every single new record? Also, I think it was in one of your other posts (although maybe I'm getting post-ers confused) that you were using an auto-entered Record ID for comparsion, which meant that your method in that case would not work with simultaneous databases being used. You may of course be handing the same iPad around a range of users, but I still think your method would be er... 'fragile'.
On the file issue, when you look in the Form-Database under Show window, is the other file still open, hidden?
I am no longer using the crazy method of finding the last Serial and then doing a search Serial>$Variable. I am using the correct method which is just setting the Serial field in the Database file to Validate Always and Unique and it works. I must have missed setting both buttons last time when I said it didn't work. And yes, I realized my old method was fragile and I ran into a lot of problems with it (all fixable) but I am still glad to be away from it.
As for the other question, it's a great idea to check that. It'll be a few days before I am back in the office but if this is the case, then maybe a simple Close Window command at the end of the script will work. I'll let you know. =]