Read Modified By column with pnpjs
سؤال
I want to select the fields I call and get the Modified By field - what's the correct way to do this?
sp.web.lists
.getByTitle(myList)
.items.select(['myId', 'Modified', 'Modified By'])
.getAll()
.then(items=> {
.....
}) .catch(e=> console.log(e) )
It works fine if I take out the Modified By - I also tried Editor and had the same error.
المحلول
Editor (Modified by) and Author are people fields. People fields is just a type of a lookup field.
When using REST (or PnPjs), you will notice that all lookup fields should be referenced by their internal name, plus Id
at the end.
For example
Author
field should be referenced asAuthorId
- MyCustomLookupField should be referenced as
MyCustomLookupFieldId
- etc.
Example of a list item. Notice Id
at the end of the lookup fields
Attachments: false
AuthorId: 10
ComplianceAssetId: null
ContentTypeId: "0x004E9DF1CD4F6A40448A5354540B3D2852"
Created: "2020-10-07T23:14:39Z"
EditorId: 10
FileSystemObjectType: 0
GUID: "19689c78-d238-4d02-ac5a-161cf8e7e0e0"
ID: 1
Id: 1
Modified: "2020-10-07T23:14:39Z"
OData__UIVersionString: "1.0"
ServerRedirectedEmbedUri: null
ServerRedirectedEmbedUrl: ""
Title: "Test List"
Example of getting Modified by with
const items = await sp.web.lists.getByTitle("TestList").items.select("ID, Modified, EditorId").getAll();
console.log(items);
If you want to get User name instead if just an id, you will need to expand the lookup field like so:
const items = await sp.web.lists.getByTitle("TestList").items.select("ID, Modified, Editor/Title").expand("Editor").getAll();
console.log(items);
لا تنتمي إلى sharepoint.stackexchange