Friday, January 23, 2015

How to display gentle reminders for incomplete SharePoint User Profile?

Ability to find people in organization and skills is one of my favorite feature of SharePoint. However, it's obvious that it's useful only when employees complete and keep their profiles up to date. At minimum, I see a great value in completing user's office location, department, contact information, manager information, profile picture, "About Me" and skills information. While some of these pieces of information (like department, manager, office location etc.) comes from Active Directory (or other any source for that matter), information such as "About Me", Profile Picture, "Ask me about" are best filled (and should beJ) out by users. But many employees don't take a few moments to provide this information and there is no way (as far as I know) to send them automatic reminders about their incomplete profile. Well, who likes to be overwhelmed with those reminders?

So I thought of giving them a gentle reminder when they visit a certain page, like an intranet home page. The reminder could be in the form of short-living (5 seconds), one liner message that appears on top right corner when one or more profile property is not filled out. Example below:

I created a Web Part which can be dropped on the page where you want the users to see these gentle reminders. The web part can be configured with:

  1. Tokenized Error Message. Allowed tokens are {0} which will be replaced with link to user profile and {1} which will be replaced with comma separated list of properties which are NOT filled out
  2. Comma separated list of profile properties that you want to check for completeness

Well, it can be enhanced with other things, but enough to get started right now:

  1. Start Date and End Date (imagine you are running a "profile complete" campaign)
  2. Time Frame (display messages only during mornings?)

Most of the code resides in JavaScript, a snippet of which is given below:

   1:  <SharePoint:ScriptLink ID="ScriptLink3" name="SP.Runtime.js" runat="server"
   2:   
   3:     ondemand="false" localizable="false" loadafterui="true" />  
   4:   
   5:  <SharePoint:ScriptLink ID="ScriptLink1" name="SP.js" runat="server"
   6:   
   7:      ondemand="false" localizable="false" loadafterui="true" />  
   8:   
   9:  <SharePoint:ScriptLink ID="ScriptLink2" name="SP.UserProfiles.js" runat="server"
  10:   
  11:      ondemand="false" localizable="false" loadafterui="true" />  
  12:   
  13:  <script type="text/javascript">  
  14:   
  15:  "use strict";  
  16:   
  17:      $(function () {  
  18:   
  19:  var personProperties;  
  20:   
  21:  var propertiesToCheck = "COMMA SEPARATED LIST OF PROPS";  
  22:   
  23:  var notifyMessage = "TOKENIZED ERROR MESSAGE GOES HERE";//
  24:   
  25:  // Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
  26:   
  27:          SP.SOD.executeOrDelayUntilScriptLoaded(getUserProperties, 'core.js');  
  28:   
  29:   
  30:  function getUserProperties() {  
  31:   
  32:   
  33:  // Get the current client context and PeopleManager instance.
  34:   
  35:  var clientContext = new SP.ClientContext.get_current();  
  36:   
  37:  var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);  
  38:   
  39:   
  40:  // Get user properties for the target user.
  41:   
  42:  // To get the PersonProperties object for the current user, use the
  43:   
  44:  // getMyProperties method.
  45:   
  46:   
  47:              personProperties = peopleManager.getMyProperties();  
  48:   
  49:   
  50:  // Load the PersonProperties object and send the request.
  51:   
  52:              clientContext.load(personProperties);  
  53:   
  54:              clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);  
  55:   
  56:          }  
  57:   
  58:  // This function runs if the executeQueryAsync call succeeds.
  59:   
  60:  function onRequestSuccess() {  
  61:   
  62:  var emptyProps = new Array();  
  63:   
  64:              $.each(propertiesToCheck, function (index, prop) {  
  65:   
  66:  if (SP.ScriptUtility.isNullOrEmptyString(personProperties.get_userProfileProperties()[prop.name])) {  
  67:   
  68:                      emptyProps.push(prop.title);  
  69:   
  70:                  }  
  71:   
  72:              });  
  73:   
  74:  if (emptyProps.length > 0) {  
  75:   
  76:                  SP.UI.Notify.addNotification(notifyMessage.replace("{0}", personProperties.get_userUrl()).replace("{1}", emptyProps.join(", ")), false)  
  77:   
  78:              }  
  79:   
  80:   
  81:   
  82:          }  
  83:   
  84:   
  85:  // This function runs if the executeQueryAsync call fails.
  86:   
  87:  function onRequestFail(sender, args) {  
  88:   
  89:   
  90:              SP.UI.Notify.addNotification("Error in Profile Notify Widget: " + args.get_message());  
  91:   
  92:   
  93:          }  
  94:   
  95:      });  
  96:   
  97:   
  98:  </script>  





  1.  


I think this is a simple but very powerful technique which may help our clients get the most out of SharePoint User Profiles. Hope this helps!

No comments:

Post a Comment