FileMaker Script works perfectly from Script Editor but...

I am new to AS and continually baffled, even when I succeed! I wrote a short script that does exactly what I want when I run it from Script Editor, but when I run it from a PERFORM APPLESCRIPT script step (which is how I ultimately need it to work), the only thing it seems to do is the “do script” command at the beginning and the beep I inserted at the end. It doesn’t even navigate thru the records.

I’m using FMP 8. Here’s the script exactly as I ran it except that I compacted the line spacing for this post:


tell application "FileMaker Pro"
	do script "clear usage counts" -- (a native FMP script)
	set match to ""
	go to record 1 of layout "Accounts"
	go to record 1 of layout "Batches"
	repeat with aa from 1 to number of records in layout "Accounts"
		repeat with bb from 1 to number of records in layout "Batches"
			if field "accountName" of record aa of layout "Accounts" is ¬
				field "accountName" of record bb of layout "Batches" then
				set match to match + (field "_messageCountInBatch" of record bb of layout "Batches")
			end if
		end repeat
		set field "usageCount" of record aa of layout "Accounts" to match
		set match to ""
	end repeat
	go to layout "Accounts"
	beep
end tell

I’ve tried it with and without the “Tell FMP” block. I’ve set up a couple other scripts that work properly, whether it’s from a script step or the Script Editor, but I can’t figure out why this one doesn’t. There’s obviously something I’m missing…

:confused:

Thia could be a problem calling a do script command inside a perform applescript command in Filemaker ( a guess)

Create a filemaker script with
Perform script “clear usage accounts” THEN
Perform applescript
tell application “FileMaker Pro”
set match to “”
go to record 1 of layout “Accounts”
go to record 1 of layout “Batches”
repeat with aa from 1 to number of records in layout “Accounts”
repeat with bb from 1 to number of records in layout “Batches”
if field “accountName” of record aa of layout “Accounts” is ¬
field “accountName” of record bb of layout “Batches” then
set match to match + (field “_messageCountInBatch” of record bb of layout “Batches”)
end if
end repeat
set field “usageCount” of record aa of layout “Accounts” to match
set match to “”
end repeat
go to layout “Accounts”
beep
end tell

Else you can save the applescript as an application and use Send Event

Just a couple of quick questions:

–Is the Filemaker database located locally or on Filemaker Server?

–Is there a reason this is being done in AppleScript versus using Filemaker’s ScriptMaker? It looks like ScriptMaker could accomplish much of the routine, taking advantage of the Let() functionality. Maybe if you did more in Scriptmaker and only used AppleScript when absolutely necessary?

I’ve always restricted using the Perform AppleScript to things FileMaker simply cannot do itself, like moving files, accessing other programs for functionality, etc. Otherwise I try to use ScriptMaker and Custom Functions to do things within Filemaker itself rather than using AppleScript to direct FileMaker from within FileMaker.

Just a thought…

WEEDINNER: That was a good guess! It worked after I removed the “perform script” line. Thank you for suggesting it.

CALVINFORD: RE why I used AS instead of FMP…

I’m not a programmer but I know my way around FMP well enough to do most of what I need done. In the past, if I couldn’t do it with FMP, I didn’t bother. (BTW: I don’t use the Dev edition of FMP.) I have never seriously attempted AppleScript until a couple weeks ago when I found that FMP couldn’t do what I needed for emailing, and I couldn’t do without it. But for some reason, I just could not get this particular script to work in ScriptMaker. (Maybe I was too immersed in AppleScript?) I spent several frustrating hours on it before I finally thought I’d try my basic AS skills. I solved it in about an hour – and with less than half the lines. I will try to solve it with FMP directly again someday.

My biggest frustration with ScriptMaker is that you can’t cut/copy/paste/move blocks as groups – at least not in my version. I quickly make a mess of things becasue of that more than anything else. That’s one thing I like about AppleScript – it’s a lot easier to edit.

Thanks,

Vera

Yeah if you do alot of FileMaker development, I can’t recommend the Advanced version enough, which comes with alot of niceties. Copy-n-paste of code blocks is handy…I thought FM Pro did that, I guess only Advanced does. The new Let() functionality is a bit wierd, but does come in handy, as are custom functions. Editable tooltips are my favorite new toy in FM. :wink:

Oddly, my experience has been the opposite…if I had a buck for every time a script ran find in ScriptDebugger or Script Editor yet didn’t run from within FileMaker, I’d be rich. :wink:

Glad you got it solved in any case!

I’m seriously considering upgrading to FMP Advanced the next time. The tooltips was the one feature that almost had me sold (also custom menus), but FMP isn’t my main livelihood so I passed this time. (I’m mainly a graphic/layout designer, but I sometimes set up related FMP solutions for the same clients on the side.) I know this is an AppleScript forum, but since you’re so familiar with FMP and it’s on my mind now, can you tell me, if I set up a solution using any of the added features in Advanced (like tooltips & custom menus), would all of those features in my solution still run on my clients’ systems if all they use is the basic version?

Compatibility is my biggest concern in upgrading since I can’t ask my clients to upgrade to Advanced just because I do. I feel lucky if they’re even willing to upgrade to the latest version.

Vera

Hello

I can’t test but I assumes that the two added instructions may help.


tell application "FileMaker Pro"
	do script "clear usage counts" -- (a native FMP script)
	tell database 1 -- ADDED
	set match to ""
	go to record 1 of layout "Accounts"
	go to record 1 of layout "Batches"
	repeat with aa from 1 to number of records in layout "Accounts"
		repeat with bb from 1 to number of records in layout "Batches"
			if field "accountName" of record aa of layout "Accounts" is ¬
				field "accountName" of record bb of layout "Batches" then
				set match to match + (field "_messageCountInBatch" of record bb of layout "Batches")
			end if
		end repeat
		set field "usageCount" of record aa of layout "Accounts" to match
		set match to ""
	end repeat
	go to layout "Accounts"
	end tell -- ADDED
	beep
end tell

Yvan KOENIG (from FRANCE mardi 1 mai 2007 13:00:09)

AS far as I know any new funtionality in current versions of filemaker are not backwards compatable. Perhaps if you could get an old developer addition of the filemaker version that might help.
I use AS and filemaker a lot to increase the funtionality of my database (I am a photographer and NOT a programmer) Its a really useful friend. Be aware that when you write a perform applescript command that filemaker treats it as if its already surrounded with a tell block. ie assume
tell application “Filemaker Pro”
–actions
end tell

If its quite a complicated script then its worth aclling it from the send event script step

[apologies for the Off-Topic digression]

Same concerns I had. Tooltips and Custom Functions and Custom Menus all work fine in the non-Advanced version, they just aren’t editable from the standard version.

EDIT: And to Weedinner’s point…any new features used in advanced may only work on the same non-Advanced version. In other words, using FileMaker Pro 8 Advanced’s new features, they likely will only work with Filemaker Pro 8 “Standard”, not Filemaker Pro 7, for example. This isn’t 100% the case, but the FM Advanced manual covers how the interactions work. Filemaker 7 and 8 and 8.5 all share the same file format (Filemaker 8 databases still save with the “.fm7” extension).

Good, I’m glad to know now know FMP Advanced will be something I can use safely. The features of Advanced, along with Applescript, should allow me to do a nicer job.

Thanks for the info!

Vera.

Filemaker has no applescript way of going to the next record. Would you believe it? Luckly there a work around. Create a filemaker script that has just goto record/request/page [next] and then call it by ‘do script’.

Also get a filemaker script to calculate found count too, then pass it by clipboard or glodal variable field. Then you know how may times to repeat your loop.

Your script is the logical applescript way, well done but you soon find thing don’t work how you think, you will find do script are far faster and will use a lot, good luck.

… except that “do script” was the thing that made this particular AppleScript not work. It worked fine after I removed that line. It seems you aren’t having a problem with do script. I wish I knew why :confused: but as long as there was a way to make mine work, that’s what’s most important to me at this stage. Thanks!

Hi

You can go to the next record in a found set


tell application "FileMaker Pro Advanced"
		try
			go to layout "your layout"
			do script "find whatever"
					repeat with i from 1 to number of records of layout "your layout"
				go to record i
				--your actions				
			end repeat
					end try
	end tell