Skip to content

Instantly share code, notes, and snippets.

@beckettkev
Last active April 6, 2016 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beckettkev/392e35f0dd1cfb4f9f138fe4cceb7efe to your computer and use it in GitHub Desktop.
Save beckettkev/392e35f0dd1cfb4f9f138fe4cceb7efe to your computer and use it in GitHub Desktop.
(function (userProfiles, $) {
userProfiles.Constants = {
EndPoint: '/_api/SP.UserProfiles.PeopleManager/GetMyProperties',
Cache: {
Key: 'ProfileProperties'
}
};
//You've seen this already, move on...
userProfiles.Current = {
...
};
//Helper function fetches the profile properties and stores them in the local storage cache (callback is invoked after this process)
userProfiles.GetCurrent = function (callback) {
MyCompany.StorageCache.GetLocalStorageItemCacheForKey(
userProfiles.Constants.Cache.Key,
_spPageContextInfo.webAbsoluteUrl + userProfiles.Constants.EndPoint,
false
).then(
function (properties) {
if (typeof properties.error === 'undefined') {
var collection = typeof properties.results === 'undefined' ? properties.d : properties.results;
[
{ Name: 'Account', Property: 'AccountName' },
{ Name: 'FullName', Property: 'PreferredName' },
{ Name: 'OfficeLocation', Property: 'OfficeLocation' },
{ Name: 'Region', Property: 'Region' },
{ Name: 'Country', Property: 'Country' },
{ Name: 'Global', Property: 'Global' },
{ Name: 'Campaign', Property: 'Campaign' },
{ Name: 'Group', Property: 'Group' },
{ Name: 'Business', Property: 'Business' },
{ Name: 'Country', Property: 'CountryName' }
].map(function(item, i) {
updateProperty(item.Name, getPropertyByKey(collection, item.Property, 'Key', ''));
});
callback();
} else {
//Hold head in hands
}
});
};
})(MyCompany.UserProfiles = MyCompany.UserProfiles || {}, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment