Onload server script is not working- Service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2019 12:36 AM
Hi all,
I want to execute the below code when the homepage loads on service portal,
(function() {
var data=gs.getUserID();
var qq = new GlideRecord('pwd_enrollment');
qq.addQuery('user', data);
qq.query();
if(qq.next())
{
console.log('user has record')
}
else
{
gs.setRedirect('https://myportal.service-now.com//$pwd_enrollment_form_container.do');
}
})();
I have created one widget on homepage and added the above code on server script of that widget.
The issue is above code is not getting executed when home page loads,but if i refresh the page again code executes perfectly.
whats wrong with my code?
Please guide me guys
Thanks!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2019 08:20 AM
Were you able to make this work? I'm also looking into a way to trigger some widget code after page where the widget is included is already loaded.