I have made one webpart using spfx, on submit button its values are pushing in SP list but in SP list I want user who is currently logged in, its value should come in one of the field of Sp list, how to do in spfx.

  • If I understand your question right, you want to view Display name of current user when you click on button – Melad Batta Feb 19 '18 at 10:33
  • @Melad, yes I want to display its name in one of field of SP list – Deeksha Gupta Feb 19 '18 at 11:26

As explained in the community here, you could retrieve the current user information before pushing your data into the your list.

| improve this answer | |

You can retrieve current user information as below:


Here this is a web part context.

| improve this answer | |
  • the above commands works when the field which stores current user name in SP list is of single line of text but when I am making it person or group type then value is not coming. – Deeksha Gupta Feb 20 '18 at 11:46

this solution may help you to get Display name of current user when you click on button

public _getCurrentUser(): void{
if (Environment.type == EnvironmentType.SharePoint || Environment.type == EnvironmentType.ClassicSharePoint) {
  let User = this.context.pageContext.user.displayName;
  let html: string = '';
  html = `
    <ul class="${styles.list}">
      <li class="${styles.listItem}">
        <span class="ms-font-l">${User}</span>
  const listContainer: Element = this.domElement.querySelector('#SPList');
  listContainer.innerHTML = html;
} }
 private _setButtonEventHandlers(): void {
const webPart: UserClickWebPart = this;
this.domElement.querySelector('#GetUser').addEventListener('click', () => { this._getCurrentUser(); });}
public render(): void {
this.domElement.innerHTML = `
  <div class="${ styles.userClick }">
    <div class="${ styles.container }">
      <div class="${ styles.row }">
        <div class="${ styles.column }">
          <span class="${ styles.title }">Welcome to SharePoint!</span>
          <p class="${ styles.subTitle }">Customize SharePoint experiences using Web Parts.</p>
          <p class="${ styles.description }">${escape(this.properties.description)}</p>
          <button class="${styles.button}" id="GetUser">
          <span class="${styles.label}">CurrentUser</span>
        <div id="Global" class="${styles.container}">
        <div id="SPList"></div>
| improve this answer | |

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.