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
NordbergNordberg 

S-control to post from standard case object to custom object via a button

Hello,

I am new to S-control's and am trying to allow a user to click a button and create a new custom object record with data being copied from the case object.  Listed below is my code, I do not receive any error, I just end up with a blank page.  I could be completely off here, but any help would be greatly appreciated. 

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<title>Copy Data From Convereted Lead</title> 
<HEAD>
<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script type="text/javascript"> 

var srcObj = sforce.connection.retrieve(
    "Id, Employee_First_Name__c, Employee_Last_Name__c, Address_line_1__c", 
    "Case", ["Case"]);

var trgtObj = new sforce.SObject("Employee__c");
trgtObj.set("Employee_Last_Name__c", srcObj[0].get("Employee_Last_Name__c"));
trgtObj.set("First_Name__c", srcObj[0].get("Employee_First_Name__c"));
trgtObj.set("Street_Address__c", srcObj[0].get("Address_line_1__c"));


var saveResult = sforce.connection.create([trgtObj]);
alert(saveResult[0].getBoolean("success") — "Operation Successful" : "Operation Failed");

</script>
</HEAD>
<body>
</body>
</html>

 

werewolfwerewolf
You need to have something like a window.open or a parent.navigateToURL that redirects the page to the location of the new object (which will be a forward slash plus its ID, like "/0063000000JlLgd").  Otherwise all it will show is the blank page as you have nothing in your <body> here.
werewolfwerewolf
…or opener.location.replace would redirect your current page to the new custom button also.
dmsx2oddmsx2od
You can do it with a URL button, passing a value from the parent object to the child object.  Information is at:
http://salesforce.phollaio.com/2007/01/16/play_with_custom_links/
http://www.thoughtsonsalesforce.com/2006/10/url-structure.html
http://salesforce.phollaio.com/2007/04/02/how_to_obtain_a_field_id/

No need to use an S-Control when a URL will do.  More simple AND fewer possible browser security errors and Firefox problems.