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
CharlieLangCharlieLang 

Custom opportunity clone button

Hi,

 

I've modified some code to clone an opportunity, one issue i am getting is that when the opportunity is closing, the closedate field is changing to 01/01/2099 when i clone the record.

 

if i add in newOpp[0].CloseDate = "{!Opportunity.CloseDate}" then when i clone the record i get and error "undefined"

 

please can someone help me as this i'm a bit stuck with this!!

 

 

try{ 

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

   // ** EDIT THIS QUERY TO LIST THE FIELDS YOU WANT TO COPY **

   var result = sforce.connection.query("Select o.Type, o.StageName, o.Amount, o.AccountId, LOB__c, Policy_Reference__c, Underwriter__c, Binder_Open_Market__c, Expiry_Date__c, Source__c, Excess__c, Commission__c, Sector__c, Inception_Date__c, CloseDate, Renewal_Date__c, Broker_Contact__c, Related_Broker__c, ELTO_ERN__c, renewal_cloned_opportunity__c, ELTO_Policy_Type__c From Opportunity o WHERE o.Id = '{!Opportunity.Id}'"); 

   var newOpp = result.getArray("records"); 

   // Reset the Opp Id and reset fields to default values 

   newOpp[0].Id = ''; 
   newOpp[0].Name = "{!Opportunity.Name} - Renewal - {!YEAR( TODAY() +365)} "; 

   // ** EDIT THESE FIELDS TO SET DEFAULT ANY VALUES **
newOpp[0].StageName = "RWL - TBQ"; 
newOpp[0].CloseDate = new Date(2099, 0, 1);
newOpp[0].LOB__c = "{!Opportunity.LOB__c}";
newOpp[0].Policy_Reference__c = "{!Opportunity.Policy_Reference__c}";
newOpp[0].Underwriter__c = "{!Opportunity.Underwriter__c}";
newOpp[0].Binder_Open_Market__c = "{!Opportunity.Binder_Open_Market__c}";
newOpp[0].Source__c = "Holding Broker";
newOpp[0].Related_Broker__c = "{!Opportunity.Related_BrokerId__c}";
newOpp[0].Broker_Contact__c = "{!Opportunity.Broker_ContactId__c}";
newOpp[0].Sector__c = "{!Opportunity.Sector__c}";
newOpp[0].ELTO_ERN__c = "{!Opportunity.ELTO_ERN__c}";
newOpp[0].ELTO_Policy_Type__c = "{!Opportunity.ELTO_Policy_Type__c }";
newOpp[0].renewal_cloned_opportunity__c = "TRUE";

   var saveResult = sforce.connection.create(newOpp); 

   if (saveResult[0].getBoolean("success")) { 
      newOpp[0].id = saveResult[0].id;
      alert("New Renewal Created"); 
   } 
   else { 
      alert("Failed to create clone: " + saveResult[0]); 
   }

   // Refresh the page to display the new oppportunity
   window.location = newOpp[0].id; 
} 
catch (err) { 
   alert (err.description ); 
}

 

V1nitV1nit

Make sure the API name of the close date field is correct and also check the datatype.

This field should not be empty.