FileMaker server new record problem

Hello,

I have a script that selects a folder of photos to add to a FM photo database.

it mounts a storage drive for the photos, moves them, makes a thumb then imports different feilds into a new record in FM 8 incluing refs to the image and thumb.

This all works great when the database is on my comp.

When I move the db to the FM server, it all works until it tries to set the feilds in the new record. I get “object not found”

Here is the ofending part of the script



on tellfilemaker(pictureFileRef, newName, FinalString, thumbPic, thumbName)
	tell application "FileMaker Pro"
		do script ("Go To Photo Database")
		set newRecord to create record
		set cell "Image" of newRecord to file ((pictureFileRef) as string)
		set cell "File Name" of newRecord to newName
		set cell "Folder" of newRecord to FinalString
		set cell "Thumb" of newRecord to file ((thumbPic) as string)
		set cell "Thumb Name" of newRecord to thumbName
	end tell
end tellfilemaker


I obviously am not accessing the db on the server correctly, funny though it does create the new record.
No matter which one of these “set” commands I take out it fails at the next (first) one it encounters.

Since some of the objects are made in the script, the “Object Not Found” error must refer to the feild on the db I am trying to set.
My event log confirms this. I get the correct item and the item is where it is suppose to be.

So the Question is How do I access the feilds on a FM server?

I will provide the whole sript if needed. Its a little long and I do not think it is needed.

Thanks for the help
higashijoe

UPDATE

Though the script is making a new record, it is not the current (active) record.

higashijoe

are you embedding the images in to the FMP DB or creating a file reference to the db ?

FMP can be a little tricky somtimes:)

I am creating a reference to the image and the thumb (couldn’t figure out how to get it)

This db has to be set up with extreme ease of use for the users.

Here is the whole script, as I said it is not going to the new record. I tried to go to last record FM script but if the folder of images had more than one it just keeps writing to the record it accessed instead of moving to the next. Another thought I had was to make the new record earlier.



property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}

display dialog "Due to the amount of time it takes to complete this process. It is recommended that you use a Computer that is wired to the network when adding photos, and not a wireless Laptop.
	Cancel will stop the process"

try
	mount volume "afp://G4-800-1.local/photo" as user name "photo" with password "photo-1" --- This works school
end try

set theDate to current date
set shortDate to short date string of theDate
set theMonth to word 1 of shortDate
set theDay to word 2 of shortDate
set theYear to word 3 of shortDate
set DateString to theMonth & "/" & theDay & "/" & theYear

set theTime to time string of theDate
set theHour to word 1 of theTime as number
set DayNight to last word of theTime
if DayNight is "PM" then set theHour to theHour + 12
set theHour to theHour as text
if the length of theHour is 1 then set theHour to "0" & theHour
set theMinutes to word 2 of theTime
if the length of theMinutes is 1 then set theMinutes to "0" & theMinutes
set theSeconds to word 3 of theTime
if the length of theSeconds is 1 then set theSeconds to "0" & theSeconds
set TimeString to theHour & "-" & theMinutes & "-" & theSeconds
set FinalString to DateString & " " & TimeString

set myAlias to ("photo:Desktop:Photos") -- works school

set targFolder to choose folder -- choose folder

delay 1
tell application "Finder"
	set newList to every file of folder targFolder whose file type is in the type_list or name extension is in the extension_list -- make list of items
	set itemCount to count of newList -- Count items--Progress
	set myCount to itemCount --Progress
	set countList to itemCount
	
	display dialog "You have selected " & countList & " Images to add to FileMaker"
	
	set theFolder to make new folder at myAlias with properties {name:FinalString}
	set thumbFolder to make new folder at theFolder with properties {name:"thumbs"}
end tell

set progress to load script alias ((("Macintosh HD:Library:Scripts:Progress Script:") as text) & "Progress.scpt") -- compliments of Bruce Phillips and MacScripters

tell progress -- starts progress bar
	initialize()
	setTitle to "Transfering Images" -- puts window title in progress bar
	
	barberPole(false) -- spinning barber pole off
	setStatusTop to "Moving images to storage location" -- text above progress bar
	setMax to itemCount -- set progress to my number of files being moved
	
	repeat with i from 1 to number of items in newList
		set pictureFile to (item i of newList) as Unicode text
		set newName to name of (item i of newList)
		set thumbName to newName --Thumb name
		setStatusBottom to "Images left to move " & myCount --Sets count below progress bar
		
		tell application "Finder"
			set deletePic to (duplicate file pictureFile to thumbFolder with replacing) as Unicode text
			set thumbPic to deletePic
			set the_file to pictureFile
			set newPic to duplicate (pictureFile) to theFolder
			set astid to AppleScript's text item delimiters
			set AppleScript's text item delimiters to "."
			set thumbPic to text 1 thru text item -2 of thumbPic & " (thumb)." & text item -1 of thumbPic
			set thumbName to text 1 thru text item -2 of thumbName & " (thumb)." & text item -1 of thumbName --Thumb Name
			set AppleScript's text item delimiters to astid
			set pictureFileRef to newPic
			
			my process_image(pictureFile, thumbPic)
			
			my tellfilemaker(pictureFileRef, newName, FinalString, thumbPic, thumbName)
			
			delete deletePic
		end tell
		set myCount to (myCount - 1) -- count down for below progress bar
		increase by 1 -- this increases the progress bar	
		
	end repeat
	quit
	try
		select window of desktop
		--eject disk "photo"
	end try
end tell
tell application "Image Events" to quit

on process_image(source_path, destination_path)
	tell application "Image Events"
		activate
		set this_image to (open alias source_path)
		scale this_image to size 120
		-- Save the scaled image directly to the "thumb" folder under the doctored name.
		save this_image in file destination_path -- before in had (as JPEG)
		close this_image
	end tell
end process_image

on tellfilemaker(pictureFileRef, newName, FinalString, thumbPic, thumbName)
	tell application "FileMaker Pro"
		do script ("Go To Photo Database")
		set newRecord to create record
		set cell "Image" of newRecord to file ((pictureFileRef) as string)
		set cell "File Name" of newRecord to newName
		set cell "Folder" of newRecord to FinalString
		set cell "Thumb" of newRecord to file ((thumbPic) as string)
		set cell "Thumb Name" of newRecord to thumbName
	end tell
end tellfilemaker


As I said this fails when I try to set a cell in newRecord, I get “Object not found”

Thanks!
higashijoe

When you set NewRecord to create record it has the reference of record ID 123 of Window “Database”. That doesn’t match the object model. Therefore use a bit of FileMaker GUI script (GUI is the object model you are using). Create a script that goes to last record then call it. Basically there’s no Found Set object.

tell application "FileMaker Pro"
	show database "DatabaseName"
	go to layout "LayoutName"
	create record
	do script "last record"
	tell current record
		set cell "CellName" to "Value"
	end tell
end tell

Or go thought no GUI element direct to the object like this

tell application "FileMaker Pro"
	tell database "DatabaseName"
		tell table "TableName"
			create record
			tell last record
				set cell "CellName" to "Value"
			end tell
		end tell
	end tell
end tell

Have Fun

I have found that that best way to create an new record and add data to it is like this


tell application "FileMaker Pro Advanced"
	activate
	tell database "database name"
		go to layout "layout name"
		set nr to create new record
		tell nr
			set cell "foo" to "bar"
		end tell
	end tell
end tell

there is no need for GUI scripting and no need to call a FMP script

let me know if that helps

mm

mcgrailm, your method works on a local FileMaker, but doesn’t on a server. Thats what his problem was (Yes local, No server). For some reason Record ID 7 of window “DatabaseName” (resulting reference on new record) finds it way to the record locally. Likely because just window name resolves to database name but on server name is whole URL path to server so doesn’t match.

Direct to the object is best for server.

so could you do something like this ?

***** This is not tested *****


tell application "FileMaker Pro Advanced"
   activate
   tell database "database name"
       go to layout "layout name"
       set current record to create new record
       tell current record
           set cell "foo" to "bar"
       end
   end tell
end tell

Becuase, goto layout and current record are GUI class, then no it doesn’t work to Filemaker Server. Plus on a local filemaker your new script creates 2 records. I wouldn’t expected that but thats want it does.

Thanks Guys!

I used Bevos second option and it is working flawlessly.

Higashijoe

Second option is the fastest, good for getting and setting. No GUI to slow things down. Only thing is sorting doesn’t work in that object model path. When you are getting data you usually find a range and sort it and bring it in to AppleScript. Also a lot of do script things create current found set. Like go related so alot of the time you need option 1. And you get back into the server/local problem. Work around slow thing down even more.

Here a quick way of get a table of data

tell application "FileMaker Pro"
	tell database "DatabaseName"
		tell table "TableName"
			try
				tell (every record whose cell "KeyCell" is "Key")
					set x to it as list
				end tell
			on error
				set x to {}
			end try
		end tell
	end tell
end tell

Two thing it errors if nothing found so you have to on error. set your list to empty. The ‘it’ refers to every field/cell.

Two get list of just choosen cells then

tell application "FileMaker Pro"
	tell database "DatabaseName"
		tell table "TableName"
			try
				tell (every record whose cell "KeyCell" is "Key")
					set List1 to cell "CellName1"
					set List2 to cell "CellName2"
				end tell
			on error
				set x to {}
			end try
		end tell
	end tell
end tell

The only thing is you have to do the sort in AppleScript. Win one way loss another.

Please Filmaker, fix the server problem or have a sort option with table path with FileMaker 9.0