How can I view all unique items in a column in list?

captain_atharv 511 Reputation points
2023-05-18T10:48:26.2166667+00:00

Hi,

I am implementing the Sharepoint list feature in UI. I want to enable the filter option but for filtering I need all unique values in the list column. Which API I can use to achieve this?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,418 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,270 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,807 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 33,641 Reputation points Microsoft Vendor
    2023-05-19T05:28:33.7466667+00:00

    Hi @captain_atharv

    I will recommend you to use rest api to enable Unique Value in SharePoint. Please refer to the following code

    function EnforceListColumnUniqueValue() {
        // NOTE:You need to first create Index for the column before Enforcing Unique Value
     
        $.ajax
            ({
                // _spPageContextInfo.webAbsoluteUrl - will give absolute URL of the site where you are running the code.
                // You can replace this with other site URL where you want to apply the function
     
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('List Name')/fields/getbytitle('Column Name')",
                method: "POST",
                data: JSON.stringify({
                    '__metadata': {
                        // Type that you are modifying.
                        'type': 'SP.FieldText'
                    },
     
                    'EnforceUniqueValues': true
                }),
                headers:
                   {
                       "IF-MATCH": "*",
                       "X-HTTP-Method": "PATCH",
                       "Accept": "application/json;odata=verbose",
                       "Content-Type": "application/json;odata=verbose",
                       "X-RequestDigest": $("#__REQUESTDIGEST").val()
                   },
                success: function (data, status, xhr) {
                    console.log("Success");
                },
                error: function (xhr, status, error) {
                    console.log("Failed");
                }
            });
    }
    
    
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful