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);
    });
});

2 Answers 2

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

1
  • you have to wait for the people picker to resolve before getting the value .. Mar 23, 2017 at 7:54

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.