If you are working on a custom solution based on SPFX and fetching data from a SharePoint list, this could get bit challenging to fetch the names of users from People Picker fields, speicially if your field allowing multiple users.

I am sharing a code snippet with you which will help you to fetch the full name(s) from people picker field and for that you need to make sure that you are fetching the titles with field names and also need to expand the people picker fields as shown in the above screenshot.

let speakers: String[] = [];
    let contactPerson: string = '';
    sp.web.lists.getById(this.props.listId).items.getById(1).select('Title,EventDate,PointofContact/Title,Speakers/Title')
    .expand('PointofContact,Speakers').get().then((data) => {
      if(data['Speakers'])
      {  
        speakers = data['Speakers'].map((user) =>
        <li>{user.Title}</li>);
      }
      if(data['PointofContact'])
      {  
        if (data['PointofContact'].Title)
        {
          contactPerson = data['PointofContact'].Title;
        }else if(data['PointofContact'][0].Title)
        {
          contactPerson = data['PointofContact'][0].Title;
        }  
      }       
      this.setState({
        contactPerson: contactPerson,
        speakers: speakers
      });
    });

Adnan is six time Microsoft MVP (Since 2015) with over 16 years of extensive experience with major expertise on SharePoint, SharePoint based development, Microsoft 365, Microsoft Teams, .Net Platform and Microsoft BI. He is currently working Sr Microsoft Consultant at Olive + Goose. He is MCT Regional Lead for Pakistan Chapter since 2012. He is working on SharePoint for past 12 years and worked on different intranet/intranet solutions for private & govt. sector majorly in United states and Gulf region and have experience of working with multiple Fortune 500 companies. He is a trainer, technology evangelist and also speaks in community forums.

Leave a Reply