Onload server script is not working- Service portal

Sin
Giga Expert

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!!

5 REPLIES 5

Bhagya Lakshmi
Mega Guru

Hello, 

You can try this in another way. In HTML you will write <div onload="c.server.update()">

yea tried.Its not working 😞

manish64
Giga Guru

//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

}

Tried to use this method and it doesn't do anything.