You need to sign in to do that
Don't have an account?
bigga
Creating Opportunities with SalesforceScripting and AS
This script has issues:
tell application "SalesforceScripting" activate set CustName to "Smithtown" set OrderNum to "123456" set session to login with saved credentials set opp to make SObject set type of opp to "Opportunity" (* THESE are REQUIRED Opportunity Fields - the Opportunity is not created if these 4 objects don't have values *) opp setField named "Name" to "blahblah2" -- 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 "Opp_Name_20__c" to "123456 BLAH BLAH" -- Eventually will filled with these variables: OrderNum & " " & CustName -- opp setField named "PDS__PO_Number__c" to "123456" -- variable OrderNum -- opp setField named "PDS__Document_Number__c" to "123456" -- variable OrderNum -- opp setField named "PDS__Invoice_Number__c" to "123456" -- variable OrderNum set res5 to session create sobjects opp Id of first item of res5 set NewOppID to Id of first item of res5 as text end tell
Inserting anything into the custom opportunity fields causes the script to fail. I can understand having "required" fields, like name, but I should be able to fill custom fields with my own data.
What error message do you get, custom fields should work fine.
Sorry, I guess I wasn't thorough in my testing These custom fields are from Pervasive Datasynch - it's an appexchange app that synchs opportunities to invoices in Quickbooks.
I'd like to insert data into these three fields in a New Opportunity:
- PDS__PO_Number__c
- PDS__Document_Number__c
- PDS__Invoice_Number__c
The fourth custom field is my own - it is filled with the Opportunity Name (CustName+Number), but in reverse (Number+CustName)
Now after review, I see that the only field that works consistently is PDS__PO_Number__c - when any of the other fields are un-commented, I get:
after the
line.
However, I am able to write data to the PDS__PO_Number__c field when that's the ONLY custom field to write to.
the result object has properties success, message & statusCode, if success is false, then message & statusCode will report the reason why the create call failed.
I don't get those messages in my Applescript Editor. Here's the event log of one that succeeded:
Here's one that failed:
The only difference that I can tell is that the successful one has a new Opportunity ID, and the failed one does not. Unless I'm missing something totally obvious.
You'll have to change your script to look at the success & message properties. Id will be missing on failed creates.
Sorry to be a dunce... change the script how?
something like
if success of res5 then
--what ever you currently do with the id
else
message of res5
end fi
That's way over my dumb applescript head, Simon. I've got a post on the AS board looking for help in adding that to it to capture the errors.
Stay tuned...
I haven't come up with any "if success equals false then message" syntax, so I'm still stuck with entering data into these custom fields:
- Opp_Name_20__c
- PDS__PO_Number__c
- PDS__Document_Number__c
- PDS__Invoice_Number__c
However, I have discovered this: if the first character starts with a number ( 0 1 2 3 4 5 6 7 8 9) then the script fails. If it's a letter, or an asterisk(*) single quote(') double quote (") backslash (\) the script succeeds!
Is this a quirkiness of Salesforce.com, or the SalesforceScripting app?
There's something weird going on with the success flag, which i'll take a look at tonight, in the intermin, you can just do
to see the failure reason from the API.
Still no good. Sorry I'm such a lame scripter...
Does 1728 help any?
I uploaded a new build that addresses the problem with status code/message etc. You can just do check for updates from the help menu to get it.
And here's a full sample of creating a contact, and checking the returned SaveResult object for either the Id of the created record, or the error message indicating why the create failed.
Success! Here's the summary of all of this:
The script that creates the opportunity now works, thanks to Simon's error reporting functionality. This OrderNum variable is being sent to Salesforce as text:
If written as Text, SalesforceScripting converts the OrderNum variable into a 15 character number: in this case "140734799799680" - the script attempts to enter that long number into these two fields:
Each of those fields has an 11-character limit. Here's the error that was reported by the New Version of SalesforceScripting when trying to write to one of those fields:
I was able to fix my script by simply changing the variable OrderNum to an integer:
Now the opportunity is created correctly.