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
BrenzoBrenzo 

Onclick Javascript Button to Update Custom Checkbox on Opportunity Record

I have a page detail button the is designed to execute javascript when clicked, resulting in a custom checkbox becoming marked "true" and the page refreshing/reloading.

Here is the code I am currently working with:
 
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}

//declare the varaiable that will hold all the information
var newRecords = [];

var opp = new sforce.SObject("Opportunity");
opp.Id = '{!Opportunity.Id}';
opp.Manager_Followed_Opportunity__c = '1';

//push the information through
newRecords.push(opp);

//save the change
result = sforce.connection.update([opp]);

//refresh the page
window.location.reload();

I cannot get the box to become marked true (I have already tried  changing 
opp.Manager_Followed_Opportunity__c = '1'; to = true/True/'True'/'true' with no success.)

Thank you in advance for any help you can provide!
BalajiRanganathanBalajiRanganathan
try setting value of 1 with out quotes

opp.Manager_Followed_Opportunity__c = 1;
BrenzoBrenzo
No such luck. Upon clicking the button, the page simply refreshes. 
Derek Patrick DayaDerek Patrick Daya
Try == instead of =.
BrenzoBrenzo
Hi Derek, I've tried == instead of = with all the above values, and the checkbox still is not updated to a true/checked value upon refresh.

Any other suggestions?
David SekulesDavid Sekules
Two things: 
In line 8, try:
opp.Manager_Followed_Opportunity__c = true;

...and in Line 14, try:
result = sforce.connection.update(newRecords);

Pretty sure those ought to work.
prachi thaleprachi thale
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}

//declare the varaiable that will hold all the information
var newRecords = [];

var opp = new sforce.SObject("Opportunity");
opp.Id = '{!Opportunity.Id}';
opp.Manager_Followed_Opportunity__c = "True";

//push the information through
newRecords.push(opp);

//save the change
result = sforce.connection.update([opp]);

//refresh the page
location.reload(true);

Try this one,It should work