how to retrieve person/group column value using spfx in custom webpart

kem104 100 Reputation points
2024-07-30T18:00:46.6233333+00:00

Hi , I am trying to retrieve the person/group column in the custom webpart. In HTML table I can get the person/group column value however if the this field value is empty in some of the instances the entire html table is disappeared.

In following code, if the RC_Owner (person/group column) has value it display the value correctly, however if the RC_Owner is blank or null then in the tablecell is should display blank or empty string value instead of disappear the table.

seem like my condition is not correct in tablecell, Please guide me the correct way to get null/empty value in the custom webpart table.

I will really appreciate your help.

<td>Compliance Program</td>
      <td>${item.Program }</td>
    </tr>
    <tr>
      <td>Compliance Delegate</td>
      <td>${item.RC_Owner.Title ? item.RC_Owner.Title : ""} </td>	

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,323 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,817 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2024-07-30T18:00:46.6466667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To display a blank or empty string value in the custom webpart table when the person/group column is null or empty, you can modify the condition in the table cell as follows:

    <td>Compliance Delegate</td>
    <td>${item.RC_Owner.Title ? item.RC_Owner.Title : ""}</td>
    

    In the above code, if the RC_Owner column has a value, it will display the Title property of the RC_Owner object. If the RC_Owner column is null or empty, it will display an empty string.

    References:


  2. Haoyan Xue_MSFT 22,466 Reputation points Microsoft Vendor
    2024-07-31T01:43:22.8966667+00:00

    Hi @kem104 ,

    I'm glad to hear you solve the problem, if you have any issue about SharePoint, you are welcome to raise a ticket in this forum.I would make a brief summary of this thread:

    Issue Symptom:

    How to get a null value in a custom webpart table when retrieving the person/group column in a custom webpart.

    Current status:

    The issue has been solved. It works with isempty method as shown below.

    <td>${ isEmpty(item.Fieldname) ? ' ' : item.Fieldname.Title } </td>
    

    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!


    0 comments No comments