2

I am filling the div of a SPClientPeoplePicker with a name of a person via JQuery. Now I want SP to look after this Person without modifying this div any further.

Is it possible to use a trigger event for this? If yes which?

4

Check out the global variable SPClientPeoplePicker.SPClientPeoplePickerDict. It's an object which is containing the clientside peoplepicker of the current page. You should be able to identify your peoplepicker by searching for the element with the key peoplepickerdivID + _TopSpan for example ctl00_PlaceHolderMain_peoplePicker_TopSpan.

Resolve user

for(var key in SPClientPeoplePicker.SPClientPeoplePickerDict){
   //for every peoplepicker on the page
   var picker = SPClientPeoplePicker.SPClientPeoplePickerDict[key];
   //check out the peoplepicker object - there's a lot more you can do with it
   console.log(picker);

   //haven't found out what the second parameter does actually but it works like this 
   picker.BatchAddUserKeysOperation(['domain\\loginname'], 0);
}

Search for string (with suggestions)

for(var key in SPClientPeoplePicker.SPClientPeoplePickerDict){
   //for every peoplepicker on the page
   var picker = SPClientPeoplePicker.SPClientPeoplePickerDict[key];
   //check out the peoplepicker object - there's a lot more you can do with it
   console.log(picker);     

   //how to trigger the search 
   var searchString = 'test';
   picker.LatestSearchQueryStr = searchString;
   var someInt = picker.AddPickerSearchQuery(searchString);
   picker.ExecutePickerQuery([someInt], function(j, h) {
       var g = JSON.parse(h.m_value);
       if (picker.ShowingLocalSuggestions()) {
           var f = SPClientPeoplePicker.AugmentEntitySuggestions(picker, g, true)
             , i = picker.CurrentLocalSuggestions.length + f.length
             , e = [];
           if (f.length != 0) {
               e.push(SPClientAutoFill.BuildAutoFillSeparatorMenuItem());
               e = e.concat(f)
           }
           e = picker.CurrentLocalSuggestions.concat(e);
           e = SPClientPeoplePicker.AddAutoFillMetaData(picker, e, i);
           picker.ShowAutoFill(e)
       } else
           picker.ShowAutoFill(SPClientPeoplePicker.BuildAutoFillMenuItems(picker, g))
    }, function() {
       picker: ;picker.SetServerError()
    }, null );
}
| improve this answer | |
  • is there nothing like .trigger("resolveuser") or something like this? because I already have the persons name. I just need to select the Person itself via the SharePoint Picker – Snickbrack Oct 19 '16 at 8:42
  • @Snickbrack Isn't this exactly what the first code does? – Mx. Oct 19 '16 at 9:11
  • 1
    @Mx. The second parameter of BatchAddUserKeysOperation is the count of processed keys. The batch operation does max 10 each time, so it's just used internally in the function. It will call itself recursively until processed keys equals the length of the array you send in. So basically you will always use 0 when you call it. – Anders Aune Dec 16 '16 at 14:22
  • @AndersAune good to know! – Mx. Dec 17 '16 at 15:37

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.