
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
});
});
No Comments