In this post, I will show you how to set the current user's profile properties using the JavaScript Client Object Model (JSOM). Please refer to the 2 posts I have mentioned for any additional details around this.
Right now this functionality is only available in SharePoint Online/Office 365. If you want this functionality to come to SharePoint 2013 On-Premises, please create or up-vote on the feedback here: https://officespdev.uservoice.com/
Right now this functionality is only available in SharePoint Online/Office 365. If you want this functionality to come to SharePoint 2013 On-Premises, please create or up-vote on the feedback here: https://officespdev.uservoice.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
SP.SOD.executeFunc("sp.js", "SP.ClientContext", function(){ | |
SP.SOD.registerSod("sp.userprofiles.js", SP.Utilities.Utility.getLayoutsPageUrl("sp.userprofiles.js")); | |
SP.SOD.executeFunc("sp.userprofiles.js", "SP.UserProfiles.PeopleManager", SetCurrentUserProperties); | |
}); | |
var userProfileProperties; | |
function SetCurrentUserProperties(){ | |
//Get Current Context | |
var clientContext = SP.ClientContext.get_current(); | |
//Get Instance of People Manager Class | |
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext); | |
//Get properties of the current user | |
userProfileProperties = peopleManager.getMyProperties(); | |
//Get only the accountname instead of all the properties. | |
clientContext.load(userProfileProperties, "AccountName"); | |
//Execute the Query. | |
clientContext.executeQueryAsync(function(){ | |
//Get the account name of the current user. It will be in the following format: "i:0#.f|membership|username@yoursite.onmicrosoft.com" | |
var currentUserAccountName = userProfileProperties.get_accountName(); | |
//Set a single value property | |
peopleManager.setSingleValueProfileProperty(currentUserAccountName, "AboutMe", "Value updated from JSOM!"); | |
//Set a multivalue property | |
var multipleValues = ["SharePoint", "Office 365", "Architecture"]; | |
peopleManager.setMultiValuedProfileProperty(currentUserAccountName, "SPS-Skills", multipleValues); | |
//Execute the Query. | |
clientContext.executeQueryAsync(function(){ | |
console.log("properties updated!"); | |
}, | |
function(sender,args){ | |
//On Error | |
console.log(args.get_message()); | |
}); | |
}, function(sender,args){ | |
//On Error | |
console.log(args.get_message()); | |
}); | |
} | |
})(); |
8 comments:
thanks for posting this
Thank you.. was helpfull :)
I am trying to reorder user profile properties in office 365 like moving property from one section to another section but unfortunately i have to do the same using move up and down button which is troublesome because after 2 - 3 attempts all moved properties come back to original position, please let me know if there is any mechanism other than move up and down button to change section of properties.
Hi Sarang, Unfortunately I think the only way to reorder the properties in SPO is to do it manually.
Thanks for the post. Good article.
Is there a way to update user profile properties through JavaScript in SharePoint 2013 On-Premises
Appreciate your help!
s there a way to update user profile properties through JavaScript/RestAPI or CSOM in SharePoint 2013 On-Premises
Hi Sujit,
For SharePoint 2013, you can either use the UserProfileService.asmx or SPServices from JavaScript.
Hi Vardhaman,
I have updated the user information from scheduler & scheduler is on another server. We have migrated ADFS user in share point so network credential is not work in UserProfileService.asmx.
Post a Comment