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
Josh Davis 13Josh Davis 13 

List button to update multi select picklist field

I'd like to have a list button to update a multi-select picklist field. The javascript below runs when I click it on a related contact list on an account page (I get the alert with the Id), but the checked record does not update. I suspect it's due to the multi-select field type, because this code worked for regular picklist in this answer.
I have enabled Account Contact Relationships, and want to update the Roles field in that object with a text value ("Former resident"). Here's the code:
{!REQUIRESCRIPT('/soap/ajax/30.0/connection.js')}

try{
    var selectedRecords = {!GETRECORDIDS( $ObjectType.AccountContactRelation )};
    if(selectedRecords.length > 0){
        var recordsToUpdate = [];
        for(var i = 0; i < selectedRecords.length; i++){
            var record = new sforce.SObject("AccountContactRelation"); 
 
            record.Id = selectedRecords[i];
            record.Roles = 'Former resident;'; /* also tried without inner semicolon */
            recordsToUpdate.push(record);
alert('Updated ' + selectedRecords[i] );  /* this works */
        }

        var result = sforce.connection.update(recordsToUpdate);  /* this doesn't work */

        location.reload();
    }
    else{
        alert('Please select at least one row');
    }
}
catch(e){
    alert(e);
}
Sukanya BanekarSukanya Banekar
Hi,
Make below modification to your code.
​var result = sforce.connection.update([recordsToUpdate]);

Let me know if this works.

Thanks,
Sukanya Banekar

 
Josh Davis 13Josh Davis 13
Thank you Sukanya. It did not change the result.