Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to set scrollTop on form in backend using Client Script

Radek Homola
Kilo Expert

Hi,

is there a way how to set scroll position (scrollTop) using client script on form?

The problem is that when I try to execute .scrollTop() on window object it returns undefined. Maybe it is connected with height of body – which is 100%.

 

Does somebody have an experience with setting scroll position inside the form iframe using DOM in client script?

Thanks

9 REPLIES 9

Paul Kunze
Tera Guru

Hi,

first you need to check if your frame you want to scroll up is the main frame on the page (without /nav_to.do) or an iframe (with /nav_to.do). This is very easy to check by verifying if the frame gsft_main exists.

You can do the following in your Client Script:

if(top.gsft_main){
	top.gsft_main.scrollTo(0, 0); 	// if form is on the sub frame
} else {
	top.scrollTo(0, 0); 		// if form is on the main frame
}

It will return undefined but do the scrolling too.

Ok, I will try to implement this and let you know,

thanks.

Unfortunately, this is not working.

I tried to execute top.gsft_main.scrollTo(0, 0);  in console, but as before – result is undefined.

 

What kind of result do you expect? It has no return value (always returns undefined) but the scrolling should happen anyway.

See some documentation for reference: https://www.w3schools.com/jsref/met_win_scrollto.asp

I need to scroll to top basically. But nothing happens when called via client script or console.