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.

Looking If A Record Already Exist

Featured Replies

I am reading a folder and want to add in a FileMaker Pro table "inFIle" a record for each file found in the selected folder.

A cell called N°Prefix is to be initialize using characters 5 thru 8 of a filename.

However, there are instances where the content of N°Prefix might already exist in the "inFile". Before creating a new record I would like to verify if that record already exist. N°Prefix is to be unique and could also be indexed.

What would be the syntax for verifying if a record already exist? or where could I read/find more information about this.

Also, could this script be triggered by clicking a button inside filemaker pro?

Thanks!

Daniel

tell application "Finder"

set theCardFiles to files in folder DestinationFolder

end tell

set sortedFiles to paragraphs of (do shell script "ls -t " & (quoted form of (POSIX path of (DestinationFolder))))

tell application "FileMaker Pro Advanced"

tell database "wOrder"

repeat with i from 1 to count of sortedFiles

set theRecord to create new record at table "inFile"

tell theRecord

set cell "N°Prefix" to (text 5 thru 8 of item i of sortedFiles)

end tell

end repeat

end tell

end tell

I don't normally do the "Find" part with AppleScript. I usually just get the file names into FileMaker (global field) with AppleScript, then Loop and test each line separately, via another global field and a relationship. But here is an AppleScript that does it all within AppleScript. The names are changed to those of my file (which I already had), and other small changes.

I tested that the folder was not empty. I moved the call to the table into a tell, to be less repetitive; though it's kind of crazy nested (not a problem in AppleScript). I just did the repeat with i in the list, as that's the simplest. I removed the Finder block, as it wasn't needed.

The "find" is enclosed in a try / on error / end try, so it only creates the record if no record for the file is found.

You could comment out the FileMaker tell line, as FileMaker does not need it if this is run via Perform AppleScript; which can be run via a button.


set sortedFiles to paragraphs of (do shell script "ls -t " & (quoted form of (POSIX path of (DestinationFolder))))

if sortedFiles = {} then

	return

end if



tell application "FileMaker Pro Advanced"

	tell database "Files_Names_of_Folder_AS"

		tell table "FileNames"

			repeat with i in sortedFiles

				try

					show (every record whose cell "FileName" is equal to i)

					-- exact find, not FileMaker Find

				on error

					set theRecord to create new record

					tell theRecord

						set cell "FileName" to i

					end tell

				end try

			end repeat

		end tell

	end tell

end tell

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.