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
Nuvo MortgagesNuvo Mortgages 

Custom button to populate fields on opportunity

Hi there,

I'm using the below javascript in a cusom button to update two fields within an opportunity when clicked.
  • The field DIP_Accepted__c is a checkbox - This needs to be set to "True" when the button is clicked
  • The field Date_DIP_Accepted__c is a DateTime field - This need to populate with the current Date&Time when the button is clicked.
The button is executing but the datetime field and tick box are not populating at all.

Please can someone help let me know where I'm going wrong?

Thanks,
Ed
 
{!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")}

var oppToUpdate = new sforce.SObject("Opportunity");
console.log(oppToUpdate.DIP_Accepted__c);

  oppToUpdate.DIP_Accepted__c = true;
  oppToUpdate.Date_DIP_Accepted__c = new Date().toISOString();

  sforce.connection.update([oppToUpdate]);

  window.location.reload();

 
Artem ChernovArtem Chernov
Hi
Your oppToUpdate variable haven't record id, thats why it cannot be updated. 
Try to add this row before update the record. 
oppToUpdate.id = '{!Opportunity.Id}'