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

List button on lead to check field value of selected records


I am trying to create a custom button on the lead list view which will; -
check if any records are selected else send an error and then once records are selected check the value of a picklist and if its not the value I want, send an error message, else update the field.  So far I have the below but its ignoring my validation formula to check the picklist, I am not a coder of any sort and am trying to piece this together from what I have learnt so far but not sure I understad what I am missing...I think I need to somehow loop through all the records selected and check the value of the picklist?!?

Any help would be great

{!REQUIRESCRIPT ("/soap/ajax/24.0/connection.js")} 
var records = {!GETRECORDIDS($ObjectType.Lead)}; 

var newRecords = []; 

if (records[0] == null) { 
alert("Please select at least one row"); 

} else { 

if({!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'New Lead')} || {!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'Active')} || {!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'Engaged')} || {!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'Industry Influencer')} || {!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'Recycled')} || {!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'Disqualified')}) { 
alert('You cannot Take Ownership of this lead until it has reached the Marketing Qualified Lead (MQL) stage.\n\n If you would like this lead fast tracked to MQL, please contact Marketing.'); 

} else { 

for (var n=0; n<records.length; n++) { 
var l = new sforce.SObject("Lead"); = records[n]; 
l.OwnerId ="{!$User.Id}"; 
l.Lead_Lifecycle_Stage__c = "Sales Accepted Lead (SAL)"; 


result = sforce.connection.update(newRecords);