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
Collen Mayer 6Collen Mayer 6 

Button to check checkbox- need help with JS

All i'm trying to create a detail button that when clicked checks a checkbox.  I found some java script in one of the forums for this purpose, but am having trouble making it work.  I get an error "Cannot set property AECaseMgmt__Program_Case__c.Generate_Closing_Summary__c of undefined."  Any ideas?  Thanks.
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("AECaseMgmt__Program_Case__c"); 
c.id ="{!AECaseMgmt__Program_Case__c.Name}"; 
c.AECaseMgmt__Program_Case__c.Generate_Closing_Summary__c = true;
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();

 
Best Answer chosen by Collen Mayer 6
Medhya MahajanMedhya Mahajan
Collen, 

//If you want to update same record
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("AECaseMgmt__Program_Case__c"); 
c.id ="{!AECaseMgmt__Program_Case__c.Id}"; 
c.Generate_Closing_Summary__c = true;
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();

This should work for you.

Regards
Medhya Mahajan

All Answers

Nevlyn DSousa TicloNevlyn DSousa Ticlo
Hi Collen

change Line 4 to 
c.id ="{!AECaseMgmt__Program_Case__c.Id}";

That should solve it. Let me know if you are still facing issues

 
Medhya MahajanMedhya Mahajan
Hi , 

Try this:
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("AECaseMgmt__Program_Case__c"); 
c.id ="{!AECaseMgmt__Program_Case__c.Id}"; 
c.AECaseMgmt__Program_Case__r.Generate_Closing_Summary__c = true;
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();

Hope this helps.

Regards
Medhya Mahajan
Collen Mayer 6Collen Mayer 6
All,
I'm still having trouble making this work.  I made the suggested changes and I still get the error: "Cannot set property AECaseMgmt__Program_Case__c.Generate_Closing_Summary__c of undefined"  

Does this mean that its not finding the Program Case SObject?

Thanks advance for anymore help/suggestions you can offer.  
Medhya MahajanMedhya Mahajan
Hi Collen 

As mentioned above please try changing the line :

c.AECaseMgmt__Program_Case__c.Generate_Closing_Summary__c = true;  

to 

c.AECaseMgmt__Program_Case__r.Generate_Closing_Summary__c = true;

Mark as solved if it helps.

Regards
Medhya Mahajan
Collen Mayer 6Collen Mayer 6
Thanks.  So if I do that and use your code above I still get an error though  a slightly different one: 

"Cannot set property 'Generate_Closing_Summary__c' of undefined"

Any other thoughts?  I appreciate your help.  
Medhya MahajanMedhya Mahajan
Collen, 

//If you want to update same record
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("AECaseMgmt__Program_Case__c"); 
c.id ="{!AECaseMgmt__Program_Case__c.Id}"; 
c.Generate_Closing_Summary__c = true;
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();

This should work for you.

Regards
Medhya Mahajan
This was selected as the best answer
Collen Mayer 6Collen Mayer 6
That did it!  Thanks so much.