Setting default value for person column to current user in SharePoint 2013 using REST


Add a content editor WebPart to the New form of custom list and add the below code, replace line 18 SetUserFieldValue function parameter to your people picker column name.

Comments

  1. where is the code block???

    ReplyDelete
    Replies
    1. Anonymous12:15 AM

      Thankz, this code fixed my issue..

      Delete
  2. Anonymous2:25 AM

    I'm trying to hide the picker field after filling it so the user can't edit it. Any ideas how to extend your code with such function?

    ReplyDelete
  3. Anonymous11:27 PM

    thank

    ReplyDelete
  4. great! It really works for me. Thank you

    ReplyDelete
  5. Anonymous2:47 AM

    Where's the code??????

    ReplyDelete
    Replies
    1. If you are not able view the code in the post, then use this url.

      Delete
  6. Hi, what can I change if I want to use another user, for example domain\jcartin ?

    ReplyDelete
  7. What could be the code to add two values on the same field? thank you

    ReplyDelete
  8. Anonymous2:57 AM

    Hello Rajesh, I get correct username(in Alert) after using above script however the peoplepicker does not identify the username. Any hint?

    ReplyDelete
  9. Richard6:46 AM

    Thank you, it works perfectly for me

    ReplyDelete
  10. We have updated the sharepoint commulative updates to June, 2016 and now this script is not working, regards,

    ReplyDelete
  11. I had to change two things to get this code to work for me. I had make sure the people picker javascript library was loaded by calling
    SP.SOD.executeFunc('clientpeoplepicker.js', 'SPClientPeoplePicker', function () { // rest of code here });

    And I had to it appears SharePoint changed the naming convention for the Input field, so I used $("div[title='"+fieldName+"']").find("input"); to retrieve it instead of $("input[title='" + fieldName + "']");

    ReplyDelete

Post a Comment