4

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?

2

A list view doesn't provide a single case's ID, but instead may provide many ID values. Your code needs to use the appropriate mechanism, called GETRECORDIDS.

{!REQUIRESCRIPT('/soap/ajax/31.0/connection.js')}
var caseIds = {!GETRECORDIDS($ObjectType.Case)};
var cases = [], tempCase, result;
while(caseIds.length) {
    tempCase = new sforce.SObject('Case');
    tempCase.Id = caseIds.shift();
    tempCase.OwnerId = '{!$User.Id}';
    tempCase.Status = 'Work in Progress';
    cases.push(tempCase);
}
result = sforce.connection.update(cases);
window.top.location.href = window.top.location.href;

Some additional work may be necessary.

  • 1
    You beat me for a split second, same answer is in my clipboard :) – Boris Bachovski Sep 10 '14 at 4:07
  • @sfdcfox -- didn't you want the javascript to use !GETRECORDIDS ? – cropredy Sep 10 '14 at 4:35
  • I only had to change GETOBJECTIDS to GETRECORDIDS and it worked perfectly, thank you very much! – Nico1969 Sep 10 '14 at 4:54
  • 1
    Hey @Nico1969, can you mark this answer as accepted if it worked? – Matt Lacey Sep 10 '14 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.