+ Start a Discussion
Sakthivel ThandavarayanSakthivel Thandavarayan 

Need help with javascript custom button to mass update & refresh list views

Hi there, The below script works well on case list views. however the problem is with the refresh, after the page refresh list view changes to something else. It not showing the selected list view, instead it's showing the first view or random(not sure). 

Is there way to update records, refresh the list view and select the same list view ? 

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

var records = {!GETRECORDIDS($ObjectType.Case)}; 
var newRecords = []; 

if (records[0] == null) 

alert("Please select at least one row") 

else 

for (var n=0; n<records.length; n++) { 
var c = new sforce.SObject("Case"); 
c.id = records[n]; 
c.Status = "Canceled"; 
c.ownerid='{!$User.Id}'; 
newRecords.push(c); 


result = sforce.connection.update(newRecords); 
window.location.reload(); 
}
 
William TranWilliam Tran
Hi, not sure I follow your issue.

But if Reload does not work for you, you can use Replace:

replace(url):Replace the current document with the one at the provided URL. 

so it would be

window.location.replace("YOUR URL");

YOUR URL can be relative to Salesforce server like

 location.replace("/{!Case.Id}?retURL=%2F{!Case.Id}");

thx
Sakthivel ThandavarayanSakthivel Thandavarayan
William,

Reload is working fine. but after the reload, its going to random list view, not the one that was previously selected.

Consider I have 5 list views, and I'm in 3rd view now.
when I click the button, page reloads and list view selected now is not 3rd view. but 1st view. 

I want to reload the page and select the same list view where user left. Is that helps understanding my issue ? 




 
@Karanraj@Karanraj
Add the following lines in the java script code, which will take the user to the same list view instead of going to the first list view option.
var listview = document.querySelectorAll('[name$="fcf"]')[0].value; 
window.location.replace('/001?fcf='+listview);
Make sure to change '/001' into the prefix code of the object
 
SimplySfdcSimplySfdc
how about 
window.location.href = "/500";
 
Sakthivel ThandavarayanSakthivel Thandavarayan
Karan & SQ

Both works. Still there is an issue without styling. Sorry for not mentioning it in the question as I'm not aware this will cause UI changes.

This button is placed in case list view and users using this button on (service)console app. After winter 16 release, console list view UI changed little bit compared to the actual list view(non console apps). 

After updating the script with the solutions you provided, it redirects properly to the same list view but UI changed. 

Before clicking the button 

User-added image

After 

User-added image

Any idea what I'm missing ? 

  
Randombard2Randombard2
Hi,

Did you ever resolve this issue, we are encoutering it in our org as well, specificaly with the console the button works fine outside of that.

R
Sakthivel ThandavarayanSakthivel Thandavarayan
Unfortunately NO.... 
Parasuram Basi 4Parasuram Basi 4
Hi Sakthivel i am facing the same UI issue in list view mentioned above. Could you please share the solution if resolved
ZHANG XINGZHANG XING
Addition to @Karanraj 's answer:
const listviewId = $('[name$="fcf"] option:checked').value;
window.location.replace('/001?fcf' + listviewId )