Filter by logged in user attributes -- sharepoint online 365

asked 2022-12-25T15:20:19.327+00:00
אבראהים דניאל 1 Reputation point

How can I filter by logged in user attributes in Content query web part SharePoint online 365

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
5,974 questions
No comments
{count} votes

3 answers

Sort by: Most helpful
  1. answered 2022-12-26T09:27:30.843+00:00
    Xuyan Ding - MSFT 5,856 Reputation points Microsoft Employee

    Hi @76716164,

    You could try using the Content Search Web Part to crawl specific fields in the user profile for dynamic content rendering.
    273995-image.png
    1.Create a term set,like Location or Department.
    SharePoint admin center->More features->Term store
    273985-image.png
    273910-image.png

    2.Add a user profile property to the existing set of properties and link it to the term set just created.
    SharePoint admin center->More features->User profiles->Manage User Properties
    274025-image.png
    273986-image.png

    3.Manage the User profile of the logged-in user, fill the newly created property.
    SharePoint admin center->More features->User profiles->Manage User Profiles
    274014-image.png

    4.Create a new content type with managed metadata field linked to the newly created term set.
    273917-microsoftteams-image-40.png

    5.Attach and display the newly created content type to the list.

    6.The Content Search web part should display data that matches the newly created content type.
    274034-image.png

    7.Switch to Advanced Mode. Added an additional filter to ensure that only items whose location/department matches the location/department in the current user's user profile properties are displayed. Set the crawled property to the current user's property.
    273978-image.png

    For a concrete example you can check out this article: Filter a Content Search Webpart by a User Profile Property
    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.

    ===================
    Update the answer=============
    If you are using a modern page, you can try the Highlighted content web part. This web part has similar functionality to the Content query and Content search web part in the classic page.
    274710-image.png
    The HCWP allows more advanced filtering and sorting by a Managed Property. Managed Properties are available to filter and sort in HCWPs either through the regular filter interface or via the more customizable KQL and CAML interfaces. The HCWP is a hybrid between CQWP and Search. At present, it should not be possible to use CAML to filter user attributes, so you can try to use KQL syntax to query managed metadata.
    These two articles are about the documentation of HCWP and the basics of KQL: Advanced Highlighted Content Web Part ; KQL – The Basics

    Combined with the crawled properties of the location/department mentioned in my answer above or a mapped managed property, filter it through the HCWP. Or specific examples can refer to the use of KQL in this post: Highlighted content web part filter crawled property based on user profile attribute.
    If you're new to using managed properties in the Highlighted Content Web Part, take a look at this post for a concrete example,which covers a typical problem while using it.


    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.

    No comments

  2. answered 2022-12-27T09:58:51.937+00:00
    אבראהים דניאל 1 Reputation point

    Thanks @Xuyan Ding - MSFT for the detailed answer, but we are using modern pages , and as I understand this web part is designed to work for classic pages only
    Any other ideas ?!

    Regards,
    Daniel


  3. answered 2023-01-04T07:21:02.157+00:00
    אבראהים דניאל 1 Reputation point

    @Xuyan Ding - MSFT
    I appreciate your help, But I was trying to filter a SharePoint List Based on logged user attributes (SpList1.Colx=LoggedUser.Address for example) .
    I Can't filter a SP List (Show some rows of a List) with HCWP as I understand I can only filter file types, that's why I tried to use CQWP.

    Regards,
    Daniel