Finding in Filemaker

Hi All,

I am progressing slowly with my iCal to/from Filemaker scripts and have hit another “I’m stuck” point. What I am trying to do here is find a record based on iCAL’s Event UID, which was stored with the record when created. I just can’t seem to figure out the syntax.

As always thanks a bunch in advance.

Here is a code snippet:

tell application “iCal” to activate
tell application “System Events”
tell process “iCal”
keystroke return
keystroke “c” using {command down}
keystroke return
end tell
end tell
set TheLocation to " "
set TheDescription to " "

tell application “iCal”
activate
set cb to the clipboard
set the_cal to calendar “Exchange”
set the_event to first event of the_cal whose summary is cb
set TheUID to the (uid of the_event as string)
end tell

tell application “FileMaker Pro”
activate
tell database “GTD”
tell table “Meeting”
— Find Code here base on TheUID
set theRecord to (first record whose cell “iCALUID” = TheUID)

		-- some sort of else clause, if record is not there
		
		ELSE set theRecord to create new record
		
		--- once found or created update meeting time etc	
		
		set data of field "MeetingDate" of theRecord to my formatDate(TheStartDate)
		set data of field "MeetingTime" of theRecord to start_time_without_sec
		set data of field "MeetingEndTime" of theRecord to end_time_without_sec
	end tell
end tell

end tell



tell application “FileMaker Pro”
activate
tell database “GTD”
tell table “Meeting”
— Find Code here base on TheUID
–set theRecord to (first record whose cell “iCALUID” = TheUID)
create request
set cell “iCALUID” to TheUID
find
– some sort of else clause, if record is not there
– I’m sure there is a way to get the count of records and it may be just that I’ll look into later

        ELSE set theRecord to create new record
       
        --- once found or created update meeting time etc   
       
        set data of field "MeetingDate" of theRecord to my formatDate(TheStartDate)
        set data of field "MeetingTime" of theRecord to start_time_without_sec
        set data of field "MeetingEndTime" of theRecord to end_time_without_sec
    end tell
end tell

end tell



Thanks mcgrailm, but that did not work. I changed to the below:

tell application “FileMaker Pro”
activate
tell database “GTD”
tell table “Meeting”
create request
set cell “iCalUID” to TheUID
find
set data of field “MeetingSubject” of theRecord to TheSummary

And on the line

       set cell "iCalUID" to TheUID 

I get an Object not found error message.

Any other thoughts?

In order to perform any actions on a field, that field must be on the active layout. The error you are getting is what you usually get when the field is not present on the layout.

I guess the simple question is; “is the field iCalUID visible on your layout?”

Ok I got it now tested this on a test database with only one table and one layout


tell application "FileMaker Pro Advanced"
	create new request
	set data of cell "iCalUID" of request 1 to TheUID
	find
        --- check to see if there where records found
	if (count of records) is greater than  0  then
		--do something
        else
        create new record
        --- do the rest
	end if
end tell

OK. I can find now :slight_smile:

But now I can’t figure out how to refer to the current record in an equation. I don’t know if it is me or Filemaker 8.5 but I can’t get any of the cell stuff to work unless it is using the native applescript from within Filemaker. This is an external script running with iCal in front.

tell application “FileMaker Pro”
activate
tell database “GTD”
tell table “Meeting”
set therequest to create new request
set data of field “iCalUID” of therequest to TheUID
find
– the find works but I can’t figure out how to refer to the found record.
set temp_sub to cell “MeetingSubject” of layout 1 of window 1
display dialog temp_sub
delete therequest
end tell
end tell
end tell

try it like this …


tell application "FileMaker Pro Advanced"
	activate
	tell database "artcode" -- replace with your databse name
		tell window 1
			go to layout "artcode" -- replace with your layout name all the cells that you plan to set must be on this layout
			
			create new request
			set cell "iCalUID" of request 1 to TheUID 
			find
			set x to count of records
			-- when there is no record make one
			if x is 0 then create new record
			-- the information is unique so let be sure that is true before we apply the data
			if x is not greater than 1 then
				set cell "MeetingDate" to my formatDate(TheStartDate)
				set cell "MeetingTime" to start_time_without_sec
				set cell "MeetingEndTime" to end_time_without_sec
				
				--alternatively if the cells are in the right order you could do the same thing like this
				set data to {my formatDate(TheStartDate), start_time_without_sec, end_time_without_sec}
				
			end if
		end tell
	end tell
end tell

Here is the completed code. A couple of things I stumbled into. Like deleted the find request variable kept if from adding to the find everytime I executed the script. and then the Tell Current Record section. I’m sure there is a lot of bad programming but it works for me. Thanks to everyone for there help.


tell application "iCal" to activate
tell application "System Events"
	tell process "iCal"
		keystroke return
		keystroke "c" using {command down}
		keystroke return
	end tell
end tell
set TheLocation to " "
set TheDescription to " "

tell application "iCal"
	activate
	set cb to the clipboard
	set cb to first paragraph of cb -- first paragrah seems to be summary field only. This handles events added by exchange
	set the_cal to calendar "Exchange"
	set the_event to first event of the_cal whose summary is cb
	set TheStartDate to start date of the_event
	set TheSummary to the summary of the_event
	set TheEndDate to the end date of the_event
	set TheDescription to the description of the_event
	set TheLocation to the location of the_event
	set TheUID to the (uid of the_event as string)
	set start_time_string to (time string of TheStartDate)
	set end_time_string to (time string of TheEndDate)
	tell start_time_string
		set start_time_without_sec to (word 1 & ":" & word 2 & space & word 4)
	end tell
	tell end_time_string
		set end_time_without_sec to (word 1 & ":" & word 2 & space & word 4)
	end tell
end tell


tell application "FileMaker Pro"
	activate
	tell database "GTD"
		tell table "Meeting"
			tell window 1
				set therequest to create new request
				set data of field "iCalUID" of therequest to TheUID
				find
				delete therequest
			end tell
		end tell
	end tell
end tell

tell application "FileMaker Pro"
	tell current record
		set didfind to false
		try
			set Temp_UID to cell "TempUID"
			set didfind to true
		end try
		if didfind then
			set data of field "MeetingSubject" to TheSummary
			try
				set data of field "MeetingLocation" to TheLocation
			end try
			set data of field "iCalUID" to TheUID
			set data of field "MeetingDate" to my formatDate(TheStartDate)
			set data of field "MeetingTime" to start_time_without_sec
			set data of field "MeetingEndTime" to end_time_without_sec
			set data of field "IniCal" to "Yes"
			set data of field "Status" to "Confirmed"
			try
				set data of field "Agenda" to TheDescription
			end try
		else
			set theRecord to create new record
			set data of field "MeetingSubject" of theRecord to TheSummary
			try
				set data of field "MeetingLocation" of theRecord to TheLocation
			end try
			set data of field "iCalUID" of theRecord to TheUID
			set data of field "MeetingDate" of theRecord to my formatDate(TheStartDate)
			set data of field "MeetingTime" of theRecord to start_time_without_sec
			set data of field "MeetingEndTime" of theRecord to end_time_without_sec
			set data of field "IniCal" of theRecord to "Yes"
			set data of field "Status" of theRecord to "Confirmed"
			try
				set data of field "Agenda" of theRecord to TheDescription
			end try
			delete theRecord
		end if
		set the clipboard to TheUID
		do script "FromiCalEvent"
	end tell
end tell


on formatDate(aDate)
	try
		set fmDateString to ((month of aDate as integer) as string) & "/" & ((day of aDate as integer) as string) & "/" & ((year of aDate as integer) as string)
		return fmDateString
	on error errMsg number errNum
		error ("formatDate error: " & errMsg) number errNum
	end try
end formatDate