+ Start a Discussion
MarkerVMarkerV 

Sobj with Javascript in an s-control?

Does anyone have an example of creating a record (either task or custom object) using the API called from an S-Control using Javascript?

I've been able to create a query, but cannot figure out the syntax for creating a new record.  Using an S-control to interact with a 3rd party fulfillment center, but need to track shipping details (passed back to s-control) within SFDC.

I've found a VB example, and examples of doing other stuff with the API, but there's no good documentation or examples I can find for creating a new record.

Thanks..
gsickalgsickal
Look in the blog at http://blog.sforce.com/sforce/general_api/index.html and scroll to the blog called "Another Great Scontrol - Convert Opportunity Products to Assets".  There are several examples in this of creating new records.
MarkerVMarkerV
Thanks, but that code seems to do a heck of a lot more than I need...I can't seem to parse down just what I need:

I'm thinking the saveAssets() function is all I need, actually only part of it (renamed function to create_new_record()):

//***********************************************
function create_new_record()
 { alert("debug0")


var assets = new Array(2);




                //Checked - now create the Asset object (DynaBean).
                alert("debug1")
                var object_2_create    = new DynaBean("MY_SFDC_OBJECT_TO_UPDATE");
                //I tried var object_2_create    = new DynaBean("Opportunity");
                //most likely will do a custom object or Task
//Error occures before alter below
                 alert("debug2")
                //Set the fields on the Asset from the form element.
                var name     = "data in the field name"
                // var the rest of the fields I want to add
                //var stat     = document.getElementById(b + "-Status");


                //Setting the AccountId field on the Asset to the same as from the Opportunity.
                //Set the contact ID field to the contact ID of the contact I opened this s-control from
                object_2_create.set("ContactId","{!Contact_ID}");

                object_2_create.set("Name",name.value);
                //set other field names just as above
               

                //assets[count] = asset;

                //increment the counter.
                //count++;
        alert("debug4")
        //Call Create on the array of object_2_create records.
        var saveResult = sforceClient.Create(object_2_create);
        alert("debug5")
}

//***********************************************

But I'm getting either DynaBean is Not defined error if I use:
<script src="https://www.sforce.com/ajax/beta3/sforceclient.js" type="text/javascript"></script>

If I use:
<script src="https://www.sforce.com/ajax/beta2/sforceclient.js" type="text/javascript"></script>
I get the error
Error: uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]"  nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)"  location: "JS frame :: https://www.sforce.com/ajax/beta2/sforceclient.js :: anonymous :: line 299"  data: no]



SteveBowerSteveBower
Use Beta 3, and use:

                var object_2_create    = new Sforce.DynaBean("MY_SFDC_OBJECT_TO_UPDATE__c");

Note:  I added "Sforce." before Dynabean.  I also added "__c" (two underscores) to the name of your object since it's a custom object and that's how the API references it, by it's "real" salesforce name.

Hope it helps, Steve Bower.

andyCandyC

First of all, try using https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js

Then, make sure you use the fully qualified Sforce.Dynabean (note the different case of Dynabean to what you were using).

See how you get on.

Cheers
Andy