4

I am trying to retreive the value of a people picker using SPUtility v0.14.2 in SharePoint Online though it always returns an empty string.

My script is as follows, do I need to retrieve the value using a different method?

$(document).ready(function () {
    var facilitator = SPUtility.GetSPField("Facilitator");
    $(facilitator.Controls).focusout(function() {
        var f = facilitator.GetValue();
        console.log(f);
    });
});
3

No you cannot directly pick values from People picker fields. Reason being a people picker field is nothing but a lookup to a list where SharePoint stores various users. Some of the values associated with a people picker field are:

--> Id

--> Display Text

Still it can be done in the following way (Workaround):

Just paste the following code inside PreSaveAction()

    function PreSaveAction() 
   {
        //alert('PreSaveAction');       
        // Get People Picker Values

        function getEditorPeoplePickerValues(fieldName) 
        {   // Field Title
            var editorNames = "";
            var _PeoplePicker = $("div[title='" + fieldName + "']");

            var _PeoplePickerTopId = _PeoplePicker.attr('id');

            var ppobject = SPClientPeoplePicker.SPClientPeoplePickerDict[_PeoplePickerTopId];
            editorsInfo = ppobject.GetAllUserInfo();
            var i;
            for (i = 0; i < editorsInfo.length; ++i) {
                editorNames += editorsInfo[i].DisplayText ;
            }
            return editorNames;
        }

        var UserName =   getEditorPeoplePickerValues("You fields name");   

   }

Just enter you people picker field's name in the double quotes.

Note: I assume you have already added reference for SPUtility and Jquery.

0

I did it using only SPUtility.js without workaround.

Use

SPUtility.GetSPFieldByInternalName('Field_x0020_Internal_x0020_Name').GetValue()[0].EntityData.Email

for getting the Email Id

SPUtility.GetSPFieldByInternalName('Field_x0020_Internal_x0020_Name').GetValue()[0].DisplayText

for getting the Display Text

I am assuming it is a single user people picker. if it is Multi user people picker, just iterate on GetValue()[] array and fetch all data you need

  • you have to wait for the people picker to resolve before getting the value .. – Abdul Hameed Mar 23 '17 at 7:54

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.