Onload client script for service portal frontpage
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2018 01:25 AM
Hi,
Does anyone know if it's possible to set up an onload client script only on the service portal so when the user reach the frontpage after logging in then check some user preferences and give a message on the screen that they need to do some action like updating their email under their profile ?
Is that possible ?
Regards
Kim
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 05:35 AM
Another way it could be done is create a client callable Script Include with logic to get the user information.
Then use a UI script to retrieve the user information via GlideAjax. Also within the UI script use logic to retrieve the url information (ie. location.pathname) to check which portal is being viewed and as well as construct the redirect.
From there add the UI script as JS include to the SP theme. This will load the script throughout the portal.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 06:45 AM
Ha... very cool concept... I'll test! 😄
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2021 10:11 PM
Hello
Can you please provide a script for me ?
Appreciate your help !
Thank you.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2022 11:33 AM
Did you ever find a reasonable solution for the scenario you described?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2022 05:51 PM
It should be possible within the Header widget used in the theme (custom of course) in combination with the server script and client/link function features.
Or depending upon what information from the User account you need, it can be done with just the client controller.
For example OOTB there is a portal and user object. To access in the client controller $scope needs to be injected. From there portal and user object can be accessed like so: $scope.portal and $scope.user.
To know what properties the portal and user object contains just console.log them out:
console.log("portal", $scope.portal, "user", $scope.user)
To get the portal url suffix such as "sp" or "esc", dot-walk to url_suffix: $scope.portal.url_suffix
Now let's say it depends on their department. Access the department by again dot-walking but this time on the user object:
$scope.user.department_dv (it's nice that SN gives the display value here)
Of course if something is needed that the OOTB user object doesn't provide then a call to the server can be done.
Once you have the criteria and logic needed to determine the redirection, let's redirect using the window or location object but the angularjs services. For this you must inject the $window or $location services. Then it's pretty much the same
For example:
$window.location.href = "your redirect url"
If $window.location.href is used it should cause a full page load which means if there is an issue with the script not re-triggered this should solve that.
Hopefully this sheds some light on what is possible.