Update User Profile Property Using PNP JS in SharePoint online

In this blog. I have explained how to update the user profile property using pnp js library.

Note:- It works only on SharePoint online itself. not working for SharePoint on premises

First thing am going to retrieve all the properties of my office 365 account

import pnp from "@pnp/pnpjs"; 

//For demo purpose hard-coded the loginname of the user

let loginName = "i:0#.f|membership|vinodhvignesh@sharepointtechie.onmicrosoft.com";

pnp.sp.profiles.getPropertiesFor(loginName).then(resp => {
        let props = {}
        resp.UserProfileProperties.map(function(val){
            props[val.Key] = val.Value
        })

        console.log("props", props)
});

It will return all the properties of the supplied user

Set “setSingleValueProfileProperty” for the user

So now “AboutMe” property is returned as empty am going to update this using “setSingleValueProfileProperty” Method

let loginName = "i:0#.f|membership|vinodhvignesh@sharepointtechie.onmicrosoft.com";

//Pass the login name, property, and property value as strings

// Hard-coded the property value 'techie'

pnp.sp.profiles.setSingleValueProfileProperty(loginName, 'AboutMe', 'Techie').then(res => {
    console.log("Update success")
})

It’s updated successfully see the response below

Set “setMultiValueProfileProperty” for the user

So now “SPS-Skills” property is returned as empty am going to update this using “setMultiValuedProfileProperty” Method

let skill = ["sharepoint", "flow", "powerapps"];

//Pass the login name, property, and property value as strings

pnp.sp.profiles.setMultiValuedProfileProperty(loginName, 'SPS-Skills', skill).then(res => {
    console.log("Update success")
})

It’s updated successfully see the response below

So now you are able to update the user profile properties of the user. you can also do the same for multiple user accounts

Happy SharePointing !….

Author Profile

Vinodh
Vinodh is a Microsoft MVP for SharePoint (Office Apps and Services) having 5+ years of experience in Microsoft Technologies.

His interest and expertise includes SharePoint Online Development, PowerApps Development, Flows for SharePoint and PowerApps. Single Page Apps/Add ins for SharePoint using React, Angular. SharePoint Farm Management, 2, 3 and upto 6 tier SharePoint Farm Installation and Configuration.

Awards :
Microsoft Most Valuable Professional for SharePoint and Office 365 awarded for the year 2016, 2017 and 2018.
C# Corner Most Valuable Professional for SharePoint and Office 365 awarded for the year 2016, 2017 and 2018.
Technology Expertise :
SharePoint Online, SharePoint 2013, SharePoint 2016 and SharePoint 2019 Preview.
Intranets both Modern and Classic, SharePoint Frameworks Customisation, SharePoint Add-ins, SharePoint single page apps.
Angular 5 with Bootstrap single page apps.
Typescript, JQuery and Javascript.
Micrsoft Flow and Powerapps.
Utilised :
Microsoft Graph API, SharePoint REST, SharePoint PnP JS.
Out of Box :
Consume Content search web parts for internet publishing sites using custom display templates.
Having knowledge on SharePoint workflows and SharePoint Designer workflows.
List customisation using JS Link, JSON Formatting.
Having knowledge in Active directory management services.
Create and configure service applications in SharePoint (MMS, UPSA, SSA).
Configure Outgoing email settings using SMTP Services.

Add a Comment

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