Skip to main content
I have a custom java script that up until a few days ago was working.  As of now this fails in both my prod and sb environments.  The premis is to create an opportunity off of a case, unless one is already tied to the case.  I dont know what is wrong or why this is not working!  Any help would be appreciated.  Here is the code.

 

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}

 

var opptyObj = new sforce.SObject("Opportunity");

 

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

 

var today = new Date();

 

var sOpptyId = "{!Case.Opportunity__c}";

 

if( sOpptyId != "")

 

{

 

   alert("This case is already tied to an opportunity!");

 

}

 

else

 

{

 

   opptyObj.AccountId = "{!Case.AccountId}";

 

   opptyObj.CloseDate = sforce.internal.dateTimeToString(today);

 

   opptyObj.Description="{!Case.Description}";

 

   opptyObj.Case__c = "{!Case.Id}";

 

   opptyObj.Name = "{!Case.Subject}";

 

   opptyObj.StageName = "Estimate in Progress";

 

   opptyObj.Created_from_Case__c = "Y";

 

   opptyObj.Type = "New Business";

 

   opptyObj.Amount = .01;

 

   var opptyresult = sforce.connection.create([opptyObj]);

 

   if (opptyresult[0].success=='false')

 

   {

 

     alert("Opportunity creation failed: " + opptyresult[0].errors.message);

 

   }

 

   else

 

   {

 

     caseObj.Id = '{!Case.Id}';

 

     caseObj.Opportunity__c = opptyresult[0].id;

 

     caseObj.Status = "Estimate in Progress";

 

     var caseResult = sforce.connection.update([caseObj]);

 

     if(caseResult[0].success == 'false')

 

     {

 

       alert("Case update failed: " + caseResult[0].errors.message);

 

     }

 

     else

 

     {

 

       alert("An opportunity has been created and linked to this case.");

 

       location.reload(true);

 

     }

 

   }

 

}
14 answers
  1. Jul 23, 2013, 4:26 AM
    As Maria said Developer Board is the best place to get quick answer of it.
0/9000