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
Custom SalesCustom Sales 

List View Custom Button

I am trying to build a button in the list view to:
Change case ownership to the current user
Change the case status to work in progress

I have the following code in the detail page that works fine:

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

var caseObj = new sforce.SObject("Case");

caseObj.Id = '{!Case.Id}';

caseObj.OwnerId = '{!$User.Id}';

caseObj.Status = "Work In Progress";

var result = sforce.connection.update([caseObj]);

window.location.href=window.location.href;

but when I put the button in the list view and click on the button, nothing happens.
it is configured to execute java script as behavior and contentsouce is set to on clickjavascript

Could you guys please provide me some light?
Best Answer chosen by Custom Sales
asish1989asish1989
Hi

Try this code.

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

var updateRecord = new Array();
var myquery = "SELECT Id FROM Case";

var result = sforce.connection.query(myquery);
var records = result.getArray("records");

for(i=0; i<records.length; i++ ){
   var update_Case = records[i];
    update_Case.OwnerId = "{!$User.Id}";
    update_Case.Status = "Work In Progress";
    updateRecord.push(update_Case);
}


result = sforce.connection.update(updateRecord);
parent.location.href = parent.location.href;

Important :

If this is what you where looking for then please mark it as a solution for others benefits.

Thank You



All Answers

KevinPKevinP
I don't know what browser you're using, but if you were using chrome, you should open the view -> Developer -> Javascript console 

Click your button with the javascript console open, and see if any errors show up. if there are errors, post them here.
Custom SalesCustom Sales
thanks for your help, here is what the javascript console shows in red for a few seconds before disappearing:
Refused to set unsafe header "User-Agent"
Error in event handler for extension.onRequest: undefined Stack trace: undefined
asish1989asish1989
Hi

Try this code.

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

var updateRecord = new Array();
var myquery = "SELECT Id FROM Case";

var result = sforce.connection.query(myquery);
var records = result.getArray("records");

for(i=0; i<records.length; i++ ){
   var update_Case = records[i];
    update_Case.OwnerId = "{!$User.Id}";
    update_Case.Status = "Work In Progress";
    updateRecord.push(update_Case);
}


result = sforce.connection.update(updateRecord);
parent.location.href = parent.location.href;

Important :

If this is what you where looking for then please mark it as a solution for others benefits.

Thank You



This was selected as the best answer
Custom SalesCustom Sales
Thanks very much, it worked as expected!