Code Monkey home page Code Monkey logo

Comments (10)

patrick-rodgers avatar patrick-rodgers commented on June 11, 2024 1

After doing a little more digging it appears that lookup fields cannot be updated with ValidateUpdateListItem. I was testing with update, which is my fault as I missed initially your use of ValidateUpdateListItem.

That seemed lame so I kept digging and found this post. The below code does work for me:

const j = await sp.web.lists.getByTitle("UserFieldList").items.getById(3).validateUpdateListItem([{
    FieldName: "User1",
    FieldValue: JSON.stringify([{ "Key": "i:0#.f|membership|[email protected]" }]),
},
{
    FieldName: "Title",
    FieldValue: "Test 3 - Updated 5",
}]);

Give that a try and you should be all set.

from pnpjs.

patrick-rodgers avatar patrick-rodgers commented on June 11, 2024

Did you see the section at the bottom on resolving field names? Could be something with that maybe. Setting the Id should work so long as the name is right. What version of SharePoint are you targeting?

from pnpjs.

raymondlittle100 avatar raymondlittle100 commented on June 11, 2024

I haven't tried the link you sent so I will give it a go. I assumed since I was able to fetch the data using the field name, KIRA_CP_ContentOwnerId, and get a valid value back I should be ok to use this in the update

from pnpjs.

raymondlittle100 avatar raymondlittle100 commented on June 11, 2024

Hi,

Just tried the script you suggested, see code and result below. I'm targeting O365

Code
image

Debugging result
image

from pnpjs.

patrick-rodgers avatar patrick-rodgers commented on June 11, 2024

Did you try and update with that entity property name as the field name with success?

from pnpjs.

raymondlittle100 avatar raymondlittle100 commented on June 11, 2024

Sorry for delay. Yeah tried with field name with 'Id' and says column doesn't exist. Tried with field name from entity property name and does nothing when I pass the user id, see some screenshots below. I have also tried setting user field with login name and email address but no joy

Post Saves
valuestillblank

Save with owner as string id. Result update happens no change in valid
usersaved

save with id column name. Result is update error
uservalueasstring

save with both columns as numbers. Result is rest error about using numbers instead of strings
uservalueasnumber

from pnpjs.

patrick-rodgers avatar patrick-rodgers commented on June 11, 2024

If you try in a different list with a different user field do things work? This is starting to seem like something with this list or configuration, and I am unable to duplicate any issues with setting user fields as you describe.

from pnpjs.

raymondlittle100 avatar raymondlittle100 commented on June 11, 2024

Just tried again on a new team site with both an OOTB SP list and then in the site pages library and it didn't work. For the list I created a new list, added a new column called 'UserOne', added a new item, updated code to fetch the item, checked the entity property name which was UserOne, called then 'validateUpdateListItem' and got no save errors. When i checked the item it was updated but the user field was blank.

I followed the same process for doing this in the site pages library except i added the new field to the wiki content type and set the new pages as this first. As with the list the updated date changed but the user stayed the same.

Sample code here
https://github.com/raymondlittle100/RL-Test-SPFx-WebParts/tree/master/PnPTesting

from pnpjs.

raymondlittle100 avatar raymondlittle100 commented on June 11, 2024

Aye perfect that works

from pnpjs.

github-actions avatar github-actions commented on June 11, 2024

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.

from pnpjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.