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
dmchengdmcheng 

S-Control sample code to copy field contents?

Hello.  I need to write an S-Control to copy the contents of a custom phone number field in a Contact record to the standard Home Phone field in the same Contact record.  (I have a custom Home Phone field in Leads and it won't feed into the standard Home Phone in Contact during the conversion.)

I have general programming experience with VBA, T-SQL, and tiny bit of Ruby, but I don't know where to start with S-Controls.  Can anyone point me to S-Control sample code that does this kind of copy function?

Thanks
David
ApprivoApprivo
here you go. try this. replace {!Contact_Custom_Phone} with the name of your custom field
 

<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>

<script type="text/javascript">

// get session id and initialize the sforceClient object

sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}");

//check everything is ok

if (sforceClient.getSessionId().indexOf("!API_Session_ID") != -1) {

displayMessage("You are not logged in");

} else {

//Update the contact

var recObject = new Sforce.Dynabean("Contact");

recObject.set("id", "{!Contact_ID}");

recObject.set("Phone", "{!Contact_Custom_Phone}");

var saveResults = sforceClient.Update(recObject);

parent.location.href = "/{!Contact_ID}";

}

-->

</script>

dmchengdmcheng
Hi, thanks for your reply.  I get an error "Bad Link Definition" when I try to save the S-Control.  Here's what I have, my custom field is "Lead_Home_Phone"


<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script type="text/javascript">

// get session id and initialize the sforceClient object
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}");


//check everything is ok
if (sforceClient.getSessionId().indexOf("!API_Session_ID") != -1) {
  displayMessage("You are not logged in");
} else {
//Update the contact
  var recObject = new Sforce.Dynabean("Contact");
  recObject.set("id", "{!Contact_ID}");
  recObject.set("HomePhone", "{!Lead_Home_Phone}");
  var saveResults = sforceClient.Update(recObject);
  parent.location.href = "/{!Contact_ID}";
}

-->

</script>
dmchengdmcheng
I see what I did wrong - I didn't specify !Contact with Lead_Home_Phone.  I changed that and it saves correctly.
jahutchjahutch
I'm looking to do a similar thing on an opportunity.  I need to copy the Amount field to a field called Plan_Forecast_Amount_c. I've tried to modify the code, but I'm not sure of the syntax to reference the two fields.  What names do I use ?