Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 8068 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi! I'm new here so bare with me. I'm also pretty new to FMP.

One of my scripts is launched via a button. The button will start a FM Script which will make it so that the only record is the found set is the current record, then launch an applescript.

The applescript will grab some data from the web, parse it, then set some fields in the found record with the grabbed data.

This usually works fine, but if an errant user decides that while they are waiting for the script to run, and clicks on one of my navigation buttons which can change the found set (a list of all unpaid accounts, for example), then the applescript will write data across ALL records in the found set. I had a minor disaster last week where data was overwritten in about 30 records because of this. I'm just glad they didn't do "show all records".

So, I need to do one of two things.

1) Make it so that while the script is running, the user cannot change the found set. Possibly by disabling the buttons in question. I'm not sure if this is possible.

2) Make the applescript so that immediately before writing data it will check to make sure there is only one record in the found set. If not, it will quit gracefully. I can't figure out how to do this either from the dictionary. Any tips?

To write data I use "set data field "fieldname" to "data"". Is there a better way to do this that won't operate on ALL found records?

Thanks!

Posted

Here's a sample script:


tell application "FileMaker Pro"

tell front database

with transaction

set recordID to ID of current record

-- perform the rest of your procedure here

.

.

.

--Now set the record based on the record ID

set cell "MyTextField" of (first record whose ID = recordID) to "DATA"

end

end tell

end tell


The "with transaction" construct prevents users from interfering with things while the script is running.

Saving the current record ID in the variable "recordID" is a good idea just in case. Then, later you know which record you need to set.

You should use the "tell Database" construct rather than the "tell Document" construct (again just in case) so that it can locate your record if somehow it gets dropped from the found set. "Tell Document" will only work with the found set of records, while "Tell Database" works with all records. Again, this may be a belt and braces approach since the transaction construct should prevent the found set from changing in the first place.

This topic is 8068 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.