Today’s post is just a small code snippet that retrieves the current user’s office location from his/her user profile (assuming that the field Office is in use, which should be the cast most of the time) with the help of SPServices. In fact, the code below is nearly identical with some that Marc D Anderson posted a few months back (had I seen this earlier, it would have saved me some time writing my own code….at least I know that my approach was right, and I learned a bit while doing it), he gives a bit more information on other possible fields that you could fetch.

GetCurrentUserOffice = function() {     var thisUser = $().SPServices.SPGetCurrentUser();     var Location;      $().SPServices({           operation: "GetUserProfileByName",           async: false,           AccountName: thisUser,           completefunc: function (xData, Status) {                $(xData.responseXML).find("PropertyData > Name:contains('Office')").each(function() {                     Location = ($(this).parent().find("Values").text());                });           }      });     return Location;}

A possible use for this is showing content based on the user’s office location, for example "The latest News from the Auckland Office". Use this function to determine the user’s office location, and use that result to fetch other content accordingly with the right filter.

Leave a Reply

Your email address will not be published. Required fields are marked *