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, a distinguished professional, boasts an impressive track record as a Microsoft MVP, having achieved this prestigious recognition for the eighth consecutive year since 2015. With an extensive career spanning over 18 years, Adnan has honed his expertise in various domains, notably excelling in SharePoint, Microsoft 365, Microsoft Teams, the .Net Platform, and Microsoft BI. Presently, he holds the esteemed position of Senior Microsoft Consultant at Olive + Goose. Notably, Adnan served as the MCT Regional Lead for the Pakistan Chapter from 2012 to 2017, showcasing his leadership and commitment to fostering growth within the tech community. His journey in the realm of SharePoint spans 14 years, during which he has undertaken diverse projects involving both intranet and internet solutions for both private and government sectors. His impact has transcended geographical boundaries, leaving a mark on projects in the United States and the Gulf region, often collaborating with Fortune 500 companies. Beyond his roles, Adnan is a dedicated educator, sharing his insights and knowledge as a trainer. He also passionately advocates for technology, frequently engaging with the community through speaking engagements in various forums. His multifaceted contributions exemplify his dedication to the tech field and his role in driving its evolution.

Leave a Reply