Filemaker dilemma. How do I automatically set data into 'found' record

G’day

I’m writing a Filemaker Data Base (8.0) to handle the booking of three rooms in a hall (a love job).

I’ve got a script that automatically books block bookings on a weekly basis, that works fine whilst not embedded into the table.

However, once embedded, it finds records by the date in a field, but only addresses the actual record that was open at the start, not the single found one.

Running as a separate script, each found record shows as selected, and I can get the ID of that record, but once embedded, the returned ID’s are always the same as the record that was last open before the search.

How can I ‘force’ the program to ‘see’ the found record please?

Edit BTW, using ‘set theID to id of current record’ doesn’t work either



set CR to ASCII character 13
set lookUpString to {"8am", "9am", "10am", "11am", "12pm", "1pm", "2pm", "3pm", "4pm", "5pm", "6pm", "7pm", "8pm", "9pm", "10pm", "11pm", "12am"}

set RoomNumber to 1
tell application "FileMaker Pro"
	tell database 1
		show every record
		delete every request
		do script FileMaker script "Force Browse Mode"
	end tell
	set TheCurrentID to ID of current record
	set TheDay to field ("Date") of record ID TheCurrentID of table "Bookings" of database 1
	set CurrentCardDate to my ParseweekDay(TheDay)
	set CurrentCardWeekDay to weekday of CurrentCardDate
	set TheBookingStartDay to field ("From 1") of record ID TheCurrentID of table "Bookings" of database 1
	set TheBookingEndDay to field ("To 1") of record ID TheCurrentID of table "Bookings" of database 1
	set flag to true
	if TheBookingStartDay = "" then
		set flag to false
		say "Please enter a, Between, Date"
	end if
	if TheBookingEndDay = "" then
		set flag to false
		say "Please enter a, To, Date"
	end if
	if flag then
		set StartDate to my ParseweekDay(TheBookingStartDay)
		-- Find next day of week that matches START
		repeat
			set tempday to weekday of StartDate
			if tempday = CurrentCardWeekDay then exit repeat
			set StartDate to StartDate + 24 * 3600
		end repeat
		set EndingDate to my ParseweekDay(TheBookingEndDay)
		-- Find previous day of week that matches FINISH
		repeat
			set tempday to weekday of EndingDate
			if tempday = CurrentCardWeekDay then exit repeat
			set EndingDate to EndingDate - 24 * 3600
		end repeat
		if EndingDate < StartDate then
			say "You have a, to, date that is before the, between, date."
		else
			set TheTime to field ("Start Enter " & RoomNumber) of record ID TheCurrentID of table "Bookings" of database 1
			set thehours to field ("Hours Enter " & RoomNumber) of record ID TheCurrentID of table "Bookings" of database 1
			set TheName to contents of cell ("Name Enter " & RoomNumber) of record ID TheCurrentID of table "Bookings" of database 1
			set ThePhone to contents of cell ("Phone Enter " & RoomNumber) of record ID TheCurrentID of table "Bookings" of database 1
			set SpeechString to ""
			if thehours = "" then set SpeechString to "Please select the hours required for the booking."
			if TheTime = "" then set SpeechString to "Please select a Start Time for the booking."
			if SpeechString = "" then
				display dialog "Do  you want to check if the weekly times are available for every " & CurrentCardWeekDay & " from " & return & return & StartDate & " to" & return & EndingDate & " inclusive." & return & return & "Start time is... " & TheTime & return & return & " For time of.... " & thehours & " hours." buttons {"Check Please", "Cancel"}
				set TimeOffSet to 1
				-- set offset
				repeat
					if TheTime as string = item TimeOffSet of lookUpString then exit repeat
					set TimeOffSet to TimeOffSet + 1
				end repeat
				set thehoursStore to thehours
				if thehours = "All Day" then
					set thehours to 17 - TimeOffSet + 1
					set thehoursStore to "All Day"
				end if
				set MaxHours to TimeOffSet + thehours - 1
				if MaxHours > 17 then
					set MaxHours to 17
					set thehoursStore to "All Day"
				end if
				set CheckDate to StartDate
				set Countweeks to 0
				set weeklist to ""
				set flag to false
				-- NOW, cycle and find daily matches
				repeat
					set theMonth to ((offset of (the month of CheckDate) in "jan feb mar apr may jun jul aug sep oct nov dec ") + 3) / 4 as integer
					set FindDate to day of CheckDate & "/" & theMonth & "/" & year of CheckDate as string
					set Countweeks to Countweeks + 1
					tell database 1
						show every record
						delete every request
						do script FileMaker script "Force Find Mode"
						set (create new request)'s cell "Date" to FindDate
						do script "Find 2"
					end tell
					set TheID to ID of record 1
					say TheID
					set HoursList to contents of cell ("Hall " & RoomNumber) of record ID TheID of table "Bookings" of database 1
					repeat with x from TimeOffSet to MaxHours
						set HourCheck to item x of lookUpString
						if HoursList ≠ "" then
							set checkflag to false
							repeat with y from 1 to number of words of HoursList
								if HourCheck = word y of HoursList then
									set flag to true
									set checkflag to true
									exit repeat
								end if
							end repeat
							if checkflag and (CheckDate is not in weeklist) then set weeklist to weeklist & CheckDate & CR
						end if
					end repeat
					set CheckDate to CheckDate + (7 * 24 * 3600)
					if CheckDate > EndingDate then exit repeat
				end repeat
				tell database 1
					show every record
					delete every request
					go to record ID TheCurrentID
					do script FileMaker script "Force Browse Mode"
				end tell
				if not flag then
					say "The booking for " & thehours & " hours on every " & CurrentCardWeekDay & " starting at " & TheTime & " for " & Countweeks & " weeks is available."
					delay 0.5
					say "Do you want to proceed"
					display dialog "Do  you want to proceed with the weekly bookings for every " & CurrentCardWeekDay & " from " & return & return & StartDate & " to " & return & EndingDate & " inclusive." & return & return & "Total weeks = " & Countweeks & return & return & "Start time is... " & TheTime & return & return & " For time of.... " & thehours & " hours." buttons {"Book them Please", "Cancel"}
					
					set SpeechString to ""
					if TheName = "" then set SpeechString to "Please enter name and details for the booking."
					if ThePhone = "" then set SpeechString to SpeechString & " Please enter a contact phone number."
					if SpeechString = "" then
						set CheckDate to StartDate
						-- NOW, cycle and book daily matches
						repeat
							set theMonth to ((offset of (the month of CheckDate) in "jan feb mar apr may jun jul aug sep oct nov dec ") + 3) / 4 as integer
							set FindDate to day of CheckDate & "/" & theMonth & "/" & year of CheckDate as string
							tell database 1
								show every record
								delete every request
								do script FileMaker script "Force Find Mode"
								set (create new request)'s cell "Date" to FindDate
								do script "Find 2"
							end tell
							set TheID to ID of record 1
							say TheID
							set HoursList to cell ("Hall " & RoomNumber) of record ID TheID of table "Bookings" of database 1
							repeat with x from TimeOffSet to MaxHours
								set HourCheck to item x of lookUpString
								set HoursList to HoursList & CR & HourCheck
							end repeat
							set cell ("Hall " & RoomNumber) of record ID TheID of table "Bookings" of database 1 to HoursList
							set field ("Hours " & RoomNumber & "." & TimeOffSet) of record ID TheID of table "Bookings" of database 1 to thehoursStore
							set field ("Booking Name " & RoomNumber & "." & TimeOffSet) of record ID TheID of table "Bookings" of database 1 to TheName
							set field ("Phone Number " & RoomNumber & "." & TimeOffSet) of record ID TheID of table "Bookings" of database 1 to ThePhone
							set CheckDate to CheckDate + (7 * 24 * 3600)
							if CheckDate > EndingDate then exit repeat
						end repeat
						set contents of cell ("Name Enter " & RoomNumber) of record ID TheCurrentID of table "Bookings" of database 1 to ""
						set contents of cell ("Phone Enter " & RoomNumber) of record ID TheCurrentID of table "Bookings" of database 1 to ""
						if thehoursStore = "All Day" then
							if TimeOffSet = 1 then
								say "The weekly booking for all day from 8am has been made."
							else
								
								say "The weekly booking for the rest of the Day at " & TheTime & " has been made."
							end if
						else
							say "The weekly booking for " & thehours & " hours at " & TheTime & " has been made."
						end if
						tell database 1
							show every record
							delete every request
							go to record ID TheCurrentID
							do script "Force Browse Mode"
						end tell
					else
						say SpeechString
						tell database 1
							show every record
							delete every request
							go to record ID TheCurrentID
							do script "Force Browse Mode"
						end tell
					end if
				else
					tell database 1
						show every record
						delete every request
						go to record ID TheCurrentID
						do script "Force Browse Mode"
					end tell
					say "There are conflicting bookings for that period."
					set DisplayErrors to "There is a conflict of the following dates." & return & return
					set DisplayErrors to DisplayErrors & weeklist & return
					display dialog DisplayErrors buttons "OK"
				end if
			else
				say SpeechString
			end if
		end if
	end if
end tell

CurrentCardWeekDay

on ParseweekDay(TheDay)
	set x to 1
	set DayString to ""
	repeat
		if item x of TheDay = "/" then exit repeat
		set DayString to DayString & item x of TheDay
		set x to x + 1
	end repeat
	set x to x + 1
	set MonthString to ""
	repeat
		if item x of TheDay = "/" then exit repeat
		set MonthString to MonthString & item x of TheDay
		set x to x + 1
	end repeat
	set x to x + 1
	set YearString to ""
	repeat with y from x to length of TheDay
		set YearString to YearString & item y of TheDay
	end repeat
	set TheDate to current date
	set time of TheDate to 0
	set day of TheDate to DayString
	set month of TheDate to MonthString
	set year of TheDate to YearString
	return TheDate
end ParseweekDay

Model: intel Core 2 Duo iMac
AppleScript: 2.1.1
Browser: Safari 3.0.4
Operating System: Mac OS X (10.5)

Hi Santa,

Personally, I have had trouble with FMP AppleScripting a find.
I discovered too much inconsistency so I opted for a compromise.

I setup two scripts in FMP:

“enterFind” and “performFind”

When I want to find a record I use the “id” that I setup for the record
and not the internal FMP id for the record.

I work everyday in FMP and this is the only thing that I have found to
be consistent.

The “enterFind” FMP script is only two steps “Enter Browse Mose” and then “Enter Find Mode[Pause]”
Then for “performFind” one step “Perform Find”


tell application "FileMaker Pro Advanced"
	tell database 1
		tell window 1
			do script "enterFind"
			set cell "id" to theID
			do script "performFind"
		end tell
	end tell
end tell

PS. If you don’t mind, next time point out the trouble areas of your
script. I want to make sure I am replying to the correct area.

Hope this helps.

Craig

I don’t have alot of time to diagnose the specific problem you have, but maybe I can offer advice, if you can humor me:

–are you runnung this database on a FileMaker Server?

–are you running this script internal to FileMaker, or an external script acting upon FileMaker?

Thanks!