I

noticed an enhancement request from Matt Beran on Twitter over the weekend. The enhancement request was for an easier way to end a user impersonation session. Currently, you have to click the impersonation icon, wait for the dialog to appear, and select your original account to end an impersonation session. While this might not be a huge issue for some people, it can get kind of old if you’re trying to quickly do a lot of testing or troubleshooting that requires frequent user impersonations. This post explains how you can create a UI script to add a button that will end impersonation and return you to your original session in a single click!

One-Click Unimpersonate Button

This solution leverages some ideas I presented in a previous post about impersonating users from any record in the system. Check it out if you’re interested in other nice ways to make the user-impersonation process more useful and convenient.

The simplest way to add this functionality is to create a clickable image that will end the user impersonation and add it to the page header. The challenge is to do this without hacking the out-of-box UI macro and breaking upgrades to the impersonate functionality in the future. Fortunately this can all be accomplished with the creation of a global UI script! Here’s how you can set it up.

‘AddUnimpersonate Button’ UI script
Name: AddUnimpersonate Button
Global: True
Description: Add a button during user impersonations to allow one-click return to original session.
Script:

addLoadEvent(addUnimpersonateButton);

function addUnimpersonateButton(){
    try{
        //Show un-impersonate icon if a user is being impersonated
        if($('impersonating_toggle_id').value != ''){
            //Insert the clickable icon in the dom
            $('impersonate_span').insert(
                '<span id="unimpersonate_span" class="icon-power" style="padding-left:5px; cursor:pointer;cursor:hand; font-size: 20px; visibility: visible" title="End impersonation" onclick="unimpersonateMe();" />'
            );
        }
    }catch(e){}
}

function unimpersonateMe(){
    //Return the user to their original session
    top.location.href = 'ui_page_process.do?sys_id=b071b5dc0a0a0a7900846d21db8e4db6&sys_user='+ $('impersonating_toggle_id').value;
}