Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
(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