SharePoint Online A Complete Guide to Getting and Setting Fields Value using PnP JS in SPFx June 24, 2020October 12, 2025 Ravichandran Krishnasamy8 Comments π This article has moved! Please visit the updated version here: π Go to Updated Article Share this: Share on Facebook (Opens in new window) Facebook Share on X (Opens in new window) X Share on LinkedIn (Opens in new window) LinkedIn Share on WhatsApp (Opens in new window) WhatsApp Email a link to a friend (Opens in new window) Email Print (Opens in new window) Print Like Loading... Related
Can you made this post for Create operation? In PnP SPFx Control React, the PeoplePicker provided selected people data like this: [{ id: “i:0#.f | membership | person1@someurl.com” imageInitials: “P1” mageUrl: “https://someurl.com/sites/MyName/_layouts/15/userphoto.aspx? accountname=person1%40someurl.com&size=M” oginName: “i:0#.f | membership | person1@someurl.com” optionalText: “” secondaryText: “person1@someurl.com” tertiaryText: “” text: “Person 1” }] Is there any way to Create or Update an item without using Person/Group’s id? LikeLiked by 1 person Reply
Getting user id is very simple import { IWebEnsureUserResult } from “@pnp/sp/site-users/”; const result: IWebEnsureUserResult = await web.ensureUser(“i:0#.f|membership|user@domain.onmicrosoft.com”); let userid = result.data.Id; check this URL for more details https://pnp.github.io/pnpjs/sp/webs/#ensureuser LikeLiked by 1 person Reply
Hi There, EnsureUser :”Checks whether the specified login name belongs to a valid user in the web. If the user doesn’t exist, adds the user to the web” I see a problem, If you use ensureuser in your code. It will work if you are an administrator. If the logged in user is a visitor to the site – How do we allow him to add the user to the web? Any thoughts on this?? LikeLike
When setting a multi value choice column the code you provided above no longer works. Instead of: Locations: { results: multiChoice } Just assign the string array directly i.e.) Locations: multiChoice LikeLike Reply
When setting a single value MMS column, the Β Β "__metadata": { "type": "SP.Taxonomy.TaxonomyFieldValue" } element is no longer needed and will result in an error if left in. LikeLike Reply
Same goes for URL columns you no longer need the "__metadata": { type: "SP.FieldUrlValue" } element LikeLike Reply
Can you made this post for Create operation?
In PnP SPFx Control React, the PeoplePicker provided selected people data like this:
[{
id: “i:0#.f | membership | person1@someurl.com”
imageInitials: “P1”
mageUrl: “https://someurl.com/sites/MyName/_layouts/15/userphoto.aspx?
accountname=person1%40someurl.com&size=M”
oginName: “i:0#.f | membership | person1@someurl.com”
optionalText: “”
secondaryText: “person1@someurl.com”
tertiaryText: “”
text: “Person 1”
}]
Is there any way to Create or Update an item without using Person/Group’s id?
LikeLiked by 1 person
Getting user id is very simple
import { IWebEnsureUserResult } from “@pnp/sp/site-users/”;
const result: IWebEnsureUserResult = await web.ensureUser(“i:0#.f|membership|user@domain.onmicrosoft.com”);
let userid = result.data.Id;
check this URL for more details
https://pnp.github.io/pnpjs/sp/webs/#ensureuser
LikeLiked by 1 person
Hi There,
EnsureUser :”Checks whether the specified login name belongs to a valid user in the web. If the user doesn’t exist, adds the user to the web”
I see a problem, If you use ensureuser in your code. It will work if you are an administrator.
If the logged in user is a visitor to the site – How do we allow him to add the user to the web?
Any thoughts on this??
LikeLike
At the end user entry will be added by SharePoint backend service not by current user
LikeLike
thanks a lot for your effort
LikeLike
When setting a multi value choice column the code you provided above no longer works. Instead of:
Locations: { results: multiChoice }
Just assign the string array directly i.e.)
Locations: multiChoice
LikeLike
When setting a single value MMS column, the
Β Β "__metadata": { "type": "SP.Taxonomy.TaxonomyFieldValue"}element is no longer needed and will result in an error if left in.LikeLike
Same goes for URL columns you no longer need the
"__metadata": { type: "SP.FieldUrlValue"}elementLikeLike