function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mkchourasiamkchourasia 

Creating a object in the S-Control

I am trying override the Clone button functionality so that while cloniong we can add all the related object entries. I am facing an issue when I am creating the new object in S-Control
 
Here is the code
 
var newSPQ = new sforce.SObject("SPQs__c");
newSPQ.Account_Distributor__c='{!SPQs__c.Account_Distributor__c}';
newSPQ.Additional_Terms___c='{!SPQs__c.Additional_Terms___c}';
newSPQ.Address__c='{!SPQs__c.Address__c}';
newSPQ.Close_Date__c='{!SPQs__c.Close_Date__c};'
newSPQ.Customer_Name__c='{!SPQs__c.Customer_Name__c}';
update newSPQ;
can someone help me so that I can correct the Mistake
 
 
 
thanks in advance
WhyserWhyser

I think the proper syntax for updating is

Code:
var result = sforce.connection.update( [newSPQ] );

so you'll need to fix your last line.

You should also check to make sure that the update was successful

Code:
if ( result[0].getBoolean("success") )
{
  // successful update, do nothing
}
else
{
  alert( "Error Occurred:\n" + result[0] );
}


 

mkchourasiamkchourasia
But this needs ID to be created in advance, how can I get that
mkchourasiamkchourasia
I got the solution for the above question, thanks a lot for all your help
 
 
sforceClient.init(API_SESSION_ID, API_SERVER_URL);
window.setTimeout(";", 1000);

var newSPQs = new Array();
var newSPQ= new DynaBean("SPQs__c");
newSPQ.set("Account_Distributor__c",'{!SPQs__c.Account_Distributor__c}');
newSPQ.set("Additional_Terms_Visible_to_Customers__c",'{!SPQs__c.Additional_Terms_Visible_to_Customers__c}');
newSPQ.set("Address__c",'{!SPQs__c.Address__c}');
....
newSPQs[0]=newSPQ;
var saveResult = sforceClient.Create(newSPQs);
if (saveResult[0] == null)
{
alert("Sucess");
}
else{
alert("Failure");
}
WhyserWhyser
What version of AJAX are you using?
 
I think they stopped using Dynabeans for a long time now, unless I am out of the loop!
 
And yes, I misread your question above, because you asked to create an object, not to update it (I got it confused with the code you provided in which you attempted to update).
 
In the case of creating an object, you don't need an ID, Salesforce will create a new ID for you.


Message Edited by Whyser on 06-03-2008 02:20 PM
werewolfwerewolf
It's true, that sforceClient stuff is from a beta version of the AJAX toolkit from years ago.  Use the latest version as Whyser suggests.