I am creating an SPFX webpart and i have to call pnp/sp to check if a list item exist and if it isn't i will create a new list item. this is my code for creating a new list item:

 return sp.web.lists.getByTitle(qnaListTrackingListName).items.add({
                LastUpdated: d.toDateString(),
                LastPublished: null,
                LockedById: currentUser.Id,
                LockedReleaseTime: d.toDateString()
            }).then((result: ItemAddResult) => {
               return result.data;

it creates my item successfully however i want it to return the list item details including the userfield ( i need the email). currently it is only returning the id. how do i expand it to include the email address as well?


GUID: "64797cb7-9c7c-408e-b848-d899440ea634"
ID: 19
Id: 19
LastPublished: null
LastUpdated: "2018-09-24T16:00:00Z"
LockedById: 10
LockedByStringId: "10"
LockedReleaseTime: "2018-09-24T16:00:00Z"
Modified: "2018-09-25T15:45:09Z"

do i need to call a get get list item with filter and expand?


Based on their Github Page:

// this result will have two properties "data" and "item"
// data is what was returned from SharePoint after the add operation
// and item is an object of type item representing the REST query to that item
// so you can immediately chain off that

Given that, what you're accessing is just the data property. If you need the details of the item, you need to use result.item instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.