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
02-15-2019 12:48 AM
Hello,
You can try this in another way. In HTML you will write <div onload="c.server.update()">
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2019 12:55 AM
yea tried.Its not working 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2019 01:12 AM
//put below code in client script and
$scope.$on('$viewContentLoaded', function() {
c.server.get({trigger:'call'}).then(function(r) { c.data.price = r.data.price; });
});
// server side
if(input.trigger=='call'){
call ur server side function
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2019 08:13 AM
Tried to use this method and it doesn't do anything.