0

I want to set default selected user on people picker?

<NormalPeoplePicker
                onChange={this._onChange.bind(this)}
                onResolveSuggestions={this._onFilterChanged}
                getTextFromItem={(persona: IPersonaProps) => persona.primaryText}
                pickerSuggestionsProps={suggestionProps}
                className={'ms-PeoplePicker'}
                key={'normal'}
                itemLimit={1}
                defaultSelectedItems={()}


              />

How to use defaultSelectedItems? Thanks

  • You mean the current logged in user should be set as default in a people picker? – Sohail Shaikh Oct 10 '18 at 10:53
  • yes, the loged user should be set as default – maaa Oct 10 '18 at 10:59
  • I have added the code below in answers. Please don't forget to upvote and mark the answer as accepted in case it helped you! – Sohail Shaikh Oct 11 '18 at 17:48
0

You can achieve this using REST API:

$(document).ready(function () {

var userid = _spPageContextInfo.userId;

function GetUserLogin() {
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";

var requestHeaders = { "accept" : "application/json;odata=verbose" };

$.ajax({
  url : requestUri,
  contentType : "application/json;odata=verbose",
  headers : requestHeaders,
  success : QuerySuccess,
  error : QueryError
});
}

function QuerySuccess(data, request){
  //removes the claims encoding
  var loginName = data.d.LoginName.split('|')[1];
  $("div[title='PeoplePickerColumnName']").val(loginName);
}

function QueryError(error) {
  alert(error);
}

GetUserLogin();

});

Reference

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.