none
Read Person or Group field properties using Client-side code RRS feed

  • Question

  • Hi,

    We have a SharePoint list having few columns of Single Line of Text, Choice, Number fields and one Person or Group field. We customized NewForm.aspx to add some Client side code.

    But, the query is while a new record is being added, user provides his user id or email address to 'Person or Group' field and presses CTRL+K or clicks Peoplepicker control, the user is resolved. But, he also wants properties of resolved user in Person or Group field to get populated in other fields once the user id is resolved.

    Can we've a REST API / jQuery code to read 'Person or Group' field properties.

    Thanks,


    Kunal

    Wednesday, July 1, 2015 11:01 AM

Answers

  • Hi,

    According to your description, my understanding is that you want to get user profile properties after users type people picker.

    I have tested in my environment and it worked fine. The working demo is shown as below.

    About how to retrieve the user name which is typed in person or group field:

    var controlName 	= "People";							
    var ppDiv 		    = $("[id$='ClientPeoplePicker'][title='" + controlName + "']");	// Select the People Picker DIV
    var ppEditor 		= ppDiv.find("[title='" + controlName + "']");	// Use the PP DIV to narrow jQuery scope
    var spPP 		    = SPClientPeoplePicker.SPClientPeoplePickerDict[ppDiv[0].id];	
    spPP.AddUnresolvedUserFromEditor(true);					// Resolve the User	if (!spPP.HasInputError) 
    {
    	var userKeys = spPP.GetAllUserInfo();
    	var myUser = userKeys[0].Description;
    }
    
    console.log(myUser);

    About how to retrieve user profile properties e.g. AccountName, Email:

    var RESTURL = "http://siteUrl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='"+myUser+"'";
    
    
    GetUserInformation();
    function GetUserInformation()
    
    {
    
     var self = this;
    
     $.ajax({
    
      url: RESTURL,
    
      type: "GET",
    
      headers: {
    
       "accept": "application/json;odata=verbose",
    
      },
    
      success: function (userdata) {
        console.log(userdata);
        console.log(userdata.d.AccountName);
        console.log(userdata.d.Email);   
      },
    
      error: function (error) {
    
       alert(JSON.stringify(error));
    
      }
    
     });
    }

    Thanks,

    Dean Wang


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.


    Monday, July 6, 2015 1:44 AM
    Moderator