Salesforce.com via Applescript issues

Hi All - I’m trying to script adding records to Salesforce.com - in this case, an opportunity. There’s a free scriptable app (SalesforceScripting) available to interface with the backend, but I’m stuck on a couple of issues.

Where I’m stuck is more applescript-centric, and not so much Salesforce-centric… I think.

The basic issue I’m having is writing to some custom opportunity fields via AS. In troubleshooting on the Salesforce/Apple forums, I’ve been asked by a techie to “change your script to look at the success & message properties.” When pressed for more detailed info, I got:

if success of res5 then
--what ever you currently do with the id
else
message of res5
end if

And that doesn’t work.

Here’s the gist of it: this script will eventually take variables I get from Filemaker, Mail and Address Book and create an opportunity on Salesforce.com. I can write the required, built-in fields just fine, but I’m having issues with the Custom Fields that I’ve added to opportunities.

tell application "SalesforceScripting"
	-- activate
	
	set session to login with saved credentials
	
	set CustName to "Smithtown"
	set OrderNum to "123456"
	set NumName to OrderNum & " " & CustName
	set NameNum to CustName & " " & OrderNum
	
	set opp to make SObject
	set type of opp to "Opportunity"
	
	(* THESE are REQUIRED Opportunity Fields - the Opportunity is not created if these 3 objects don't have values *)
	
	opp setField named "Name" to NameNum -- text returned of (display dialog "Name This" default answer "") -- as text -- will be filled by a variable
	opp setField named "StageName" to "Prospecting"
	opp setField named "CloseDate" to "2011-07-10"
	
	(* THESE are Custom Opportunity Fields - anything written via applescript, and the "Create SObjects" instruction fails - no opportunity created *)
	
	--	opp setField named "PDS__Document_Number__c" to OrderNum -- variable OrderNum
	--	opp setField named "PDS__Invoice_Number__c" to OrderNum -- variable OrderNum

	(* Except for THIS custom field. It works just fine *)

	opp setField named "PDS__PO_Number__c" to OrderNum -- variable OrderNum

	(* This custom field works sometimes, but not reliably *)
	
	--	opp setField named "Opp_Name_20__c" to text of NumName

	(* this is the part that actually writes the data to Salesforce.com *)
	
	set MakeOpp to session create sobjects opp
	Id of first item of MakeOpp
	set NewOppID to Id of first item of MakeOpp as text
end tell

My techie is telling me to ‘capture the errors using the success and message properties’ but I can’t find any syntax on these boards (or anywhere else) to tell me how to do this.

Below is the result of a Successful execution:

tell application "SalesforceScripting"
	login with saved credentials
		--> UserSession id "us_292"
	make new SObject
		--> SObject id "row_294"
	set type of SObject id "row_294" to "Opportunity"
	setField SObject id "row_294" named "Name" to "Smithtown 123456"
	setField SObject id "row_294" named "StageName" to "Prospecting"
	setField SObject id "row_294" named "CloseDate" to "2011-07-10"
	setField SObject id "row_294" named "PDS__PO_Number__c" to "123456"
	create UserSession id "us_292" sobjects SObject id "row_294"
		--> {SaveResult id "sr_295" of UserSession id "us_292"}
	get Id of SaveResult id "sr_295" of UserSession id "us_292"
		--> "006E0000002eYNSIA2"
	get Id of SaveResult id "sr_295" of UserSession id "us_292"
		--> "006E0000002eYNSIA2"
end tell
Result:
"006E0000002eYNSIA2"

And this is a failed one:

tell application "SalesforceScripting"
	login with saved credentials
		--> UserSession id "us_316"
	make new SObject
		--> SObject id "row_318"
	set type of SObject id "row_318" to "Opportunity"
	setField SObject id "row_318" named "Name" to "Smithtown 123456"
	setField SObject id "row_318" named "StageName" to "Prospecting"
	setField SObject id "row_318" named "CloseDate" to "2011-07-10"
	setField SObject id "row_318" named "PDS__Document_Number__c" to "123456"
	create UserSession id "us_316" sobjects SObject id "row_318"
		--> {SaveResult id "sr_319" of UserSession id "us_316"}
	get Id of SaveResult id "sr_319" of UserSession id "us_316"
		--> missing value
	get Id of SaveResult id "sr_319" of UserSession id "us_316"
		--> missing value
end tell
Result:
"missing value"

I’m guessing that the error capture/success stuff has to wrap around this part somewhere:

	set MakeOpp to session create sobjects opp
	Id of first item of MakeOpp
	set NewOppID to Id of first item of MakeOpp as text

But I’m totally lost on how to do it. My fingers are getting numb, and my eyes are starting to cross.

As always, any assistance is muy appreciated.

Model: MBP 17in 2.8 Intel
AppleScript: 2.1.2
Browser: Safari 533.20.27
Operating System: Mac OS X (10.6)

I really only need help with the basics of AS - how to write “if success, do this. Else, show message”