user422165
user422165

Reputation: 13

Sharepoint SPFx spuser getting addition fields

I'm using the SPFx with React in Typescript and able to get the SPUser, but it only has a couple of fields like displayName, email, and loginName. Is there a way to get the Department of the user? Or do I have to use PNP-JS?

Example how I get the displayName: this.props.context.pageContext.user.displayName

Is there a way to get other fields of the user?

Upvotes: 1

Views: 513

Answers (1)

Lee
Lee

Reputation: 5493

You could use REST api also.

Sample script:

 this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/sp.userprofiles.peoplemanager/GetMyProperties`, SPHttpClient.configurations.v1)
    .then((response: SPHttpClientResponse) => {
      var data= response.json();
      console.log(data);
    });

enter image description here

Upvotes: 1

Related Questions