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
HobieHobie 

Creating a OnClick Javascript List View button

I have a Custom Button that is on a Custom Object called Reviewer that will update a checkbox called "On Project" back on a Contact record.  I need a little help putting this on the List View of the Custom Object called Reviewer.  Is this possible?

Thank you very much for your help!  My code is below. 

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

var selectedReviewers = 
{!GETRECORDIDS("Contact")}; 

if(selectedReviewers.length > 0){ 
var reviewersToUpdate = []; 
for(var i=0; i<selectedReviewers.length; i++){ 
var updatedReviewer = 
new sforce.SObject("Contact"); 

updatedReviewer.Id = selectedReviewers[i]; 
updatedReviewer.On_Project__c = '1'; 

reveiwersToUpdate.push(updatedReviewer); 


var result = 
sforce.connection.update(reviewersToUpdate); 

location.reload(); 

else{ 
alert( 
"Please select at-least one record." 
); 
}
hitesh90hitesh90
Hello Hoble,

Yes, it is possible. Follow below steps to add custom list button on List View.

1. Go to Setup
2. Go to Create --> Object --> Select your custom Object ("Reviewer").
3. Scroll down to the "Search Layouts" sections.
4. Edit --> "Search Results"
5. Add your custom button.

Let me know if you have any question on this. Please mark this "Solved" if it helps.

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/

 
HobieHobie
Hitesh, thanks for the info.  However that code I wrote will not do a loop.  I'm not a programmer.  So what I need help with is how to write to the code to loop through checked records on a list view screen.  Thanks for replying! 
hitesh90hitesh90
Hello Hoble,

I think you have to give your sObject name ("Reviewer") instead of Contact in below line.

Let me know if you have any question on this. Please mark this "Solved" if it helps.

Previous Code:
var selectedReviewers = {!GETRECORDIDS("Contact")};
New Code:
var selectedReviewers = {!GETRECORDIDS("Reviewer__c")};

var selectedReviewers = {!GETRECORDIDS("Contact")}; 

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/

 
HobieHobie
@Hitesh,

That did not work.  I still received the error "ReviewerToUpdate" not defined.