I've been meaning to share this functionality for a while, but I have not had the time until now.  It's a Form link UI Action on the User table, available to users with the "admin" role and to all users when looking at their own record:

_Screenshot.png

It's a quick way to reset a user's settings back to what they originally were when they first logged in.  It might be useful to give your "itil" users permission as well so your Service Desk techs can clear the settings for your users.  The user is asked to confirm the action before deleting records from the following tables:

  • Bookmarks [sys_ui_bookmark]
  • User Preferences [sys_user_preference]
  • List View customizations [sys_ui_list]
  • Tags [label]
  • Label History [label_history]
  • Notification Messages [cmn_notif_message]

 

Name: Clear User Settings

Table: User [sys_user]

Order: 100

Action name: u_clear_user_settings

Active: Checked

Show update: Checked

Client: Checked

Application: Global    (for Fuji and above)

Form link: Checked

Onclick: u_clearUserSettingsClient();

Condition: current.isValidRecord() && (gs.hasRole("admin") || gs.getUserID() == current.getValue("sys_id"))

Script:

//client function that runs 'onclick'
function u_clearUserSettingsClient() {
  var confirmMessage = "Are you sure you want to clear this user's settings?";

  //is this the user's own record?
  if (g_user.userID == g_form.getUniqueValue()){
  confirmMessage = "Are you sure you want to clear your settings?";
  }

  if(confirm(confirmMessage)) {
  gsftSubmit(null, g_form.getFormElement(), "u_clear_user_settings");   //MUST call the 'Action name' set in this UI Action
  }
}

//code that runs on server
//ensure call to server-side function with no browser errors
(function() {
  if (typeof window == 'undefined') u_clearUserSettingsServer();
})();

function u_clearUserSettingsServer() {
  //First, commit any changes to the record
  current.update();

  //get the record's sys_id
  var sysId = current.getValue("sys_id");

  var infoMessage = "Settings cleared - have the user logout then back in for the change to take effect.";
  if (gs.getUserID() == sysId){
  infoMessage = "Settings cleared - logout then back in for the change to take effect.";
  }

  //Clear Bookmarks
  var gr = new GlideRecord('sys_ui_bookmark');
  gr.addEncodedQuery('user=' + sysId);
  gr.deleteMultiple();

  //Clear User Preferences
  var gr = new GlideRecord('sys_user_preference');
  gr.addEncodedQuery('user=' + sysId);
  gr.deleteMultiple();

  //List view customizations
  var gr = new GlideRecord('sys_ui_list');
  gr.addEncodedQuery('sys_user=' + sysId);
  gr.deleteMultiple();

  //Clear Tags
  var gr = new GlideRecord('label');
  gr.addEncodedQuery('owner=' + sysId);
  gr.deleteMultiple();

  //Recently Accessed records/modules
  var gr = new GlideRecord('label_history');
  gr.addEncodedQuery('user=' + sysId);
  gr.deleteMultiple();

  //Notification messages
  var gr = new GlideRecord('cmn_notif_message');
  gr.addEncodedQuery('user=' + sysId);
  gr.deleteMultiple();

  gs.addInfoMessage(infoMessage);
  action.setRedirectURL(current);
}


It will then display a message to the user to logout then back in for the change to take effect.  Not 100% sure if that is necessary, but it doesn't hurt. 

 

If you want to give your "itil" users permission to clear settings as well, change the Condition field to:

current.isValidRecord() && (gs.hasRole("itil") || gs.getUserID() == current.getValue("sys_id"))


The "gs.hasRole("itil")" snippet will return true for "admin" users as well.

 

Please let me know if there are any tables that I missed.