1

I would like to use the SPCLientPeoplePicker to generate a result set without manually typing into the people picker input field. I want to do this by javascript having the people picker control hidden.

SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePicker_TopSpan.AutoFillControl.AllOptionData - gives me all the information I need given the fact that I have manually entered something into peoplePicker_TopSpan_EditorInput. I do not know how it compiles the result in AllOptionData...

It is not sufficent just to change value in the editorInput with javascript. Some kind of event is triggered at user input and I cant find out which and where.

There is also a hidden input field which I have also tried to change value on but without further luck.

I would like it all to be done client-side with javascript. How can it be done?

4
  • So if i understand this correctly, you only want the result set irrespective of whether the people picker is there or not? Why do you want this? Do you want to get only 1 user or all the users and do you want to prepopulate the people picker? Check this : jasonscript.wordpress.com/2013/08/07/…
    – Akhoy
    Commented Aug 24, 2015 at 15:53
  • I am only interested in the result set and I do not need to resolve the users. The informatoin I get from AllOptionData is sufficent in my scenario. Problem is I can't get the AutoFillControl to fetch the results if I do not manually type into the editorinput. What I would like is (simplified): 1. $("#peoplePicker_TopSpan_EditorInput").val("user"); 2. Value change should then trigger some event that updates the AutoFillControl. 3. Get a result set from AllOptionData with user1, user2, user3 etc.. All done in background
    – Fred
    Commented Aug 24, 2015 at 18:30
  • Can you post a screenshot of the AllOptionData that you want?
    – Akhoy
    Commented Aug 24, 2015 at 19:03
  • As you can see in the Screenshot, AllResultOptions is the suggested users based on the input field. I would like to get AllResultOptions without manually typing into the input field.
    – Fred
    Commented Aug 25, 2015 at 5:20

1 Answer 1

1

There is a way to achieve this by posting to the people picker REST api. So maybe you can build your own people picker to do the manipulation instead of relying on the OOB people picker.

Note: Replace <termtosearch> with the the appropriate term you want to search the result set with.

$.ajax( 
{        
    'url':'https://siteUrl/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser',
    'method':'POST',
    'data':JSON.stringify({
        'queryParams':{
            '__metadata':{
                'type':'SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters'
            },
            'MaximumEntitySuggestions':50,
            'PrincipalSource':15,
            'PrincipalType': 1,
            'QueryString':'<termtosearch>'
    }
    }),
    'headers':{
        'accept':'application/json;odata=verbose',
        'content-type':'application/json;odata=verbose',
        'X-RequestDigest':$('#__REQUESTDIGEST').val()
    },
    'success':function (data) { 
        var d = data; //data object will have the result set in JSON
        console.log(data);
    },
    'error':function (err) { 
        alert(JSON.stringify(err)); 
    }
});

Source: http://sharepointfieldnotes.blogspot.in/2014/06/sharepoint-2013-clientpeoplepicker.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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