In this article, I have explained how to update the user profile property using a PnP JS library. It works only on SharePoint Online, not for SharePoint on-premises.
First, I am going to retrieve all the properties of my Office 365 account.
- import pnp from "@pnp/pnpjs";
-
-
-
- let loginName = "i:0#.f|membership|[email protected]";
-
- 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. I am going to update this using the “setSingleValueProfileProperty” method.
- let loginName = "i:0#.f|membership|[email protected]";
-
-
-
-
-
- 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. I am going to update this using the “setMultiValuedProfileProperty” method.
- let skill = ["sharepoint", "flow", "powerapps"];
-
-
-
- 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!