Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Protecting the Found Set while an Applescript runs

Featured Replies

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!

Use:

Set cell "Field" of current record to "data"

Or:

Set cell "Field" of record "record number" to "data"

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.

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.