Ending impersonations via Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2016 01:52 AM
Hi All
I just want to share a little feature I made.
We have enabled the automatic redirect of users without roles to the Service Portal - Redirect to Service Portal after login
This however has a conquence when impersonating an end user - you will not be able to get back to the normal UI to end the impersonation without first logging out of the syste.
This could be quite annoying when performing tests in the system where you need to verify someting in the Service Portal as an end user.
So I have created a new menu item in the header menu, to end any active impersonation. It ends the impersonation and reloads the service portal as "your self".
The feature is added to a modified version of the Stock Header.
Service Script
//Check if we are impersonating a user
if (gs.getImpersonatingUserName() !== gs.getUserName() && gs.getImpersonatingUserName() !== null) {
data.is_impersonating = true;
data.impersonating = gs.getImpersonatingUserName();
}
else
data.is_impersonating = false;
Client Script
$scope.impersonate = function(user_name) {
if (!user_name)
return;
$http.post('/api/now/ui/impersonate/' + user_name, {}).success(function() {
$scope.show_error = false;
window.location = "/sp";
}).error(function(response) {
if (response.error) {
$scope.show_error = true;
$scope.error = response.error;
$log.error("Impersonate failed", response.error);
}
});
}
New line added to the div containing the dropdown menu (code below does not generate the menu shown in my screen shot but is taken from the Stock Header widget)
<ul class="dropdown-menu">
<li><a ng-href="?id=user_profile&sys_id={{::user.sys_id}}">${Profile}</a></li>
<li><a href="{{::portal.logoutUrl}}">${Logout}</a></li>
<!-- Line below is the new line to add -->
<li><a ng-if="data.is_impersonating" ng-click="impersonate(data.impersonating)"><i class="fa fa-reply" style = "margin-right: 5px;"></i>${End Impersonation}</a></li>
</ul>
- Labels:
-
Service Portal
- 8,805 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2022 06:11 AM
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0676913
- In the address bar, add/replace the current URI with /impersonate_dialog.do, this directly loads the Impersonate Dialog page.
- The last option is to replace the current URI in the address bar with /logout.do, sometimes it is the only option if there is a scripted redirect method in place.