How do you perform a javascript function on a ui page onload?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2014 05:23 AM
What I want is pretty simple. I just want a javascript function to execute as soon as the page loads. I'm attempting to get this to work in a ui page.
This is how I would normally perform this
<body onload="myFunction()">
and then in the client script I would have the function
function myFunction(){
alert("Yay! This function executed on load!");
}
However in service now I get no such luck. Is there anyway I can perform this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2014 07:14 AM
I usually use the prototype method document.observe in jelly pages in ServiceNow. You can do:
document.observe("dom:loaded", function() {
//dostuff
alert("Yay! This function executed on load!");
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2014 10:56 AM
While there is nothing wrong with what you are doing, if you want to do it by using Service Now's API methods, you will have to make a call to a function called addLoadEvent(); which takes a function as a parameter.
example : addLoadEvent(loadMe);
function loadMe(){
alert('Loading');
}
Hope that helps!