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
JackieDoanJackieDoan 

Attempting to use record criteria, rather than checkbox selection, for list button

I have created a custom list button, which executes javascript. Instead of using GETRECORDIDS, I'd like to use record criteria (any related records where status = 'New'). I attempted to modify the code behind my button to accept the criteria using the sforce.connection.query, but keep getting errors. 

 

Here's the existing code:

 

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

var url = parent.location.href; 

var records = {!GETRECORDIDS($ObjectType.Contact)};
var updateRecords = []; 

if (records[0] == null) { 
alert("Please select at least one record to update."); 
} else {  
for (var a=0; a<records.length; a++) {  
var update_Contact = new sforce.SObject("Contact");  
update_Contact.Id = records[a];  
update_Contact.Status__c = "Transmit"; 
updateRecords.push(update_Contact); 
} 
result = sforce.connection.update(updateRecords); 
parent.location.href = url;  
}

 

Can anyone give me a suggestion on how to modify this so I can bypass the checkbox selection and use status  of "New" to execute the code?

 

Thanks!

sfdcfoxsfdcfox
You'd have to replace the GETRECORDIDS function in the standard library with a custom function to do it the way you're trying to. I'd suggest instead that you simply grab the current record's ID, then perform a sforce.connection.query to find the relevant records (which may not even appear in the list at the time of the button click).