0

How can I add or update people picker field in SharePoint list/library using SPServices

I tried to post the account ID it did not worked tried display name it did not worked, do you know what is the format acceptable for people picker field.

$().SPServices({
    operation: "UpdateListItems",
    batchCmd: "New",
    listName: "PersonnelRecord",
    valuepairs: [["EmployeePickerField",PostDisplayName], ["LastName",PostLastName],],
    completefunc: function (xData, Status) {

    });
0

Set person field with user id like this snippet (get current user id and set)

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.js"></script>
<script type="text/javascript">
var thisUserID = $().SPServices.SPGetCurrentUser({
    fieldName: "ID",
    debug: false
});
var title='test'
$().SPServices({
   weburl: "http://sp/sites/dev/",
   operation: "UpdateListItems",
   async: true,
   batchCmd: "New",
   listName: "TestList1",
   valuepairs: [["Title",title],["User",thisUserID]],
   completefunc: function(xData,Status){}
});
</script>

enter image description here

  • I don't want to add the current user – Mehdi Jalal Sep 30 '18 at 4:04
  • I want to add any users if I enter his email in the email box – Mehdi Jalal Sep 30 '18 at 4:04
  • Or do you know how to get the UserId based on email ID ? so that I query the ID and than process add/update – Mehdi Jalal Sep 30 '18 at 4:06
  • @Jerry, your soln was not working. in my case. i am using a separate functional inside content editor web part and called the custom function just before presaveaction() . i want to access the user , who is added/modified in the client ppl picker control field in my editform.aspx – SaMolPP Nov 6 '18 at 15:57
0

Format to update people picker field from spservice is "useridfromuserinfolist;#domain\username"

e.g "7;#microsoftdomain\m3456"

If you want to read it from people picker field on page/html then you can use below

var userLoginName = $('span.assest_pp').find('span.ms-entity-resolved div').attr("key"); // this will return you in format "domain\username"

var thisUserID = "-1;#" + userLoginName ; // here assuming we don't know the userid stored in UserInfoList.

Your value Pair should look like

 valuepairs: [["Title",title],["User",thisUserID]],

JFYI...Depending on SP2010 or SP 2013, below line will return different data but it will still work if you setting in above format.

$('span.assest_pp').find('span.ms-entity-resolved div').attr("key")

i:0#.w|domain\username - SP 2013
domain\username - SP 2010

Hope this helps..happy coding...!!!

  • you question is "How can I add or update people picker field in SharePoint list/library using SPServices"....above explain that only and if you user information is coming from AD...just focus getting is loginname and update in format "-1;#domain\username"..it should work. – Siddharth Vaghasia Sep 30 '18 at 5:31
  • I passed something like this: var UserDetail = "-1;#Username"; and it did not worked I have 2010 SharePoint – Mehdi Jalal Sep 30 '18 at 9:07
  • What is the acceptable format of data for UserPicker field in a SharePoint list using SPServices – Mehdi Jalal Sep 30 '18 at 9:10
  • Please paste you whole updated code, the format you are trying is correct....are you also passing domain name ? – Siddharth Vaghasia Oct 1 '18 at 3:28
  • Yes I did pass the domain name it did not worked. – Mehdi Jalal Oct 3 '18 at 4:56

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.