How to keep the page scroll position even after refreshing pages (both Classic UI and Portal)?

Aki18
Tera Contributor

When refreshing page (both Classic UI and Portal), the page scroll position is lost and moved to the top position of the page, which is very inconvenient...
Is there any way to keep the scroll position even after refreshing Classic UI and Portal pages?

For example, in portal page, is there any method to define that function somewhere? (Maybe in the Client controller of the widget?)


Best Regards,
Aki

1 ACCEPTED SOLUTION

Markus Kraus
Kilo Sage

 

I thought this is quite an interesting go because especially list count = 100 or with forms that have a huge activity log you tend to scroll a lot.

Also when editing huge script includes you wouldn't need to scroll a lot (note: this is currently not implemented, but will probably be in a future version).

 

So what you have to do is fork the following repository and then open up the target instance's studio and select "Import From Source Control" (where you specify the newly forked repository):

https://github.com/kr4uzi/ServiceNow-Scroll-Restore

View solution in original post

15 REPLIES 15

Thx for the info, seems i had a old cached version loaded... fixed it so please sync the repo in github and apply remote changes afterwards in servicenow.

EDIT: Fixed to work with Next Experience. For the Service Portal there is still a limitation: The scroll position is only restored for the list and form page as for all other pages, there is no technique to know when the page has actually loaded and you can restore the position.

Note: This is not working at the moment in the new Polaris UI. Only UI16 + Service Portal (ServicePortal also not on all pages - there is no "page loaded" event in service portal except for the datatable and form pages, so if you want to test it out, please use the form and list page)

Hi @Markus Kraus ,

Thank you for the update. I applied remote changes, but the scroll position still gets lost after refreshing the pages...

It works for regular list / form pages such as Incident, correct? Could you show me the gif image to show how it works for your environment?

Hi @Aki18 

 

Can you open the console and see if there are any errors?

 

Hi @Markus Kraus ,

Thank you for the video. I tried the same way in the Incident form, but still scroll position is not kept after refreshing the page...

 

  > Can you open the console and see if there are any errors?

 

Do you mean the browser's developer tool?

Here is the Chrome one of the Incident form.

Aki18_0-1687841518225.png

 

Hm the console errors would have been interesting, but I can see that there aren't any.

Note however that your repository is not yet in sync. You need to sync your repository otherwise it will not work:

MarkusKraus_0-1687850247545.png

After syncing it should hopefully work 🙂