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

Case copy fails - cant figure out why

I am trying to create a new button that runs an S Control that will take the current "Case", grab the information from specified fields, and create a new case.  I have tried several methods.  Surprisingly every time I search for information I come up with a new completely unrelated possible solution.
I have tried at least 4 different ways, and I continue to get page javascript errors "Object Expected", same error every time, line number does change.
<script language="javascript" src="/soap/ajax/8.0/connection.js" type="text/javascript"></script>
<script type="text/javascript">
function createClone()

var case = new sforce.SObject("Case");

case.RecordTypeId = "012300000000000000";
case.ContactId = "{!Case.ContactId}";
case.Applicant_Name__c = "{!Case.Applicant_Name__c}";
case.Request_ID__c = "{!Case.Request_ID__c}";
case.Product_or_Service__c = "{!Case.Product_or_Service__c}";
case.Subject = "{!Case.Subject}";
case.Origin = "{!Case.Origin}";
case.AccountId = "{!Case.AccountId}";
case.CS_Case_Number__c = "{!Case.CS_Case_Number__c}";
case.Description = "{!Case.Description}";

var result = sforce.connection.create([case]);

  if (result[0].getBoolean("success")) 
    log("new case created with id " + result[0].id);
   log("failed to create case " + result[0]);

<body onload="createClone()">

I took out the other methods I had attempted so hopefully this is readable.  I also tried creating a DynaBean("Case") and setting the values, case.set("Item",value); and then calling sforceClient.Create([case])[0]; but was met with the same result, Object Expected.  Im going to try to see if it is null values or something somewhere.  Is there a way to check that in the code I listed above?

I was able to get past the disabled View Source context menu and it looks like everything is being populated like its supposed to:


var case = new sforce.SObject("Case");
case.RecordTypeId = "0126000000098D0XXX";
//case.ContactId = "00330000004u89k";
//case.Applicant_Name__c = "TEST";
//case.Request_ID__c = "testing";
//case.Subject = "testing";
//case.Origin = "Email";
//case.AccountId = "00130000002XX";
case.CS_Case_Number__c = "00803464";
//case.Description = "test";
var result = sforce.connection.create([case]);


still getting error, Object Expected.

Try this:

var result = sforce.connection.create([case]);

Let us see what the server returned.

I actually got this working finally yesterday.  I must have had a syntax problem (user error!) somewhere, because after I deleted and started over it ended up working and I dont think I changed much from attempt #1 to attempt #3523.  Thanks for the reply though Cheenath :)