Quantcast
Channel: SharePoint 2013 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 26374

Update user profile properties using JavaScript

$
0
0

Hello

I am trying to update user profile property on SharePoint 2016 using JavaScript. My code is not throwing any error, but user profile is not getting udpated.

Also, is there a way to update ManagedMetadata type user profile property using JavaScript?

If yes, then kindly help with the pointers.

var userProfileProperties;
    //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", "Text");   

        //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());
    });

Prateek Vijay Vashistha


Viewing all articles
Browse latest Browse all 26374

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>