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

Problems Creating a button to mass update a picklist field type

Hi Everyone, I am working on an onClick Javascript button within the list view in  And I got the script below to work when the field "Add_to_Call_List__c" is a text field, however when it is a picklist type, I need to use the ISPICKVAL or CASE function.  The business need is to update this field on mass when this button is clicked on within the list view.
Would anyone know what changes I need to make to:
"callList.Add_to_Call_List__c = "TRUE";"
when I make the field type a picklist?  As this field is going to be a picklist field type at the end of the day.  Let me know if more detail is required.
Thanks in advance!
// Include and initialize the AJAX Toolkit javascript library
// Get the list of job applications that should be closed by using the
// $ObjectType merge field to indicate the type of record Ids that
// are expected.
var leadID = {!GetRecordIds($ObjectType.Lead)};
if (leadID == null || leadID.length == 0) {
alert("You need to select Leads to add to the call list.");
} else {
var leadUpdate = new Array();
for (var i = 0; i < leadID.length; i++) {
var callList = new sforce.SObject("Lead");
// Since we'll be using the update call, we must set the id
// on the new job application record.
callList.Id = leadID[i];
callList.Add_to_Call_List__c = "TRUE";
// Finally add the record to our array.
// Now make the update API call in a try statement so we can
// catch any errors. Save the resulting array so we can also
// check for problems with individual records.
var callCompleted = false;
try {
var result = sforce.connection.update(leadUpdate);
callCompleted = true;
} catch(error) {
alert("Failed to update Field with error: " + error);
// Now check for problems with individual records.
if (callCompleted) {
for (var i = 0; i < result.length; i++) {
if (!result[i].getBoolean("success")) {
alert("Job Application (id='" + leadID[i] +
"') could not be updated with error: " +
// Finally, refresh the browser to provide confirmation
// to the user that the job applications were rejected.
Please disregard this post, as this still works with a picklist field.  I will leave this in the instance someone needs the sample script above..
Thanks, Steve!  I used your code to create a few buttons. The first is an "Accept Ownership" button that lets you transfer ownership of multiple records in a search result to yourself.
Does anyone have any tips on if you need to update a custom object? using this for standard objects works fine but when I change the coding for custom object doesn't seem to work so I don't know if I am editing the right areas?