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?

1 Answer 1

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .