Sp-starter-kit: Filter WebPart "People Directory"

Created on 18 Feb 2019  路  15Comments  路  Source: pnp/sp-starter-kit

Category

  • [X] Question
  • [ ] Bug
  • [ ] Enhancement

Expected or Desired Behavior

Is there a way to filter the people you see in the webpart "People Directory" so that only specific users are shown?

For example, using an attribute of the AD account?

Observed Behavior

All users are displayed.

Thanks!

Author Feedback answered

Most helpful comment

I've had the same issue but with the out of the box people search. For this webpart I think the best thing would be to create a bespoke Result Source where you add your exclusions to the query editor (for example only show users who have a department). However, this would then provide a different experience to the out of the box search results. Microsoft now provide a mechanism to exclude certain AD synced accounts from all 365 search but it's a bit messy and you basically have to hide them from the Address list via an AD attribute. https://techcommunity.microsoft.com/t5/SharePoint-Support-Blog/Exclude-Users-From-Delve-and-SharePoint-Online-People-Search/ba-p/170731

All 15 comments

I'd like to request this as well. We have admin accounts and service accounts and hidden terminated employees who show up no matter what. Looks unprofessional and I can't really use this webpart until we can filter. Appreciate you making it and can't wait for an update.

Thank you,

I've had the same issue but with the out of the box people search. For this webpart I think the best thing would be to create a bespoke Result Source where you add your exclusions to the query editor (for example only show users who have a department). However, this would then provide a different experience to the out of the box search results. Microsoft now provide a mechanism to exclude certain AD synced accounts from all 365 search but it's a bit messy and you basically have to hide them from the Address list via an AD attribute. https://techcommunity.microsoft.com/t5/SharePoint-Support-Blog/Exclude-Users-From-Delve-and-SharePoint-Online-People-Search/ba-p/170731

mag210, if this webapp could be modified to exclude the SPS-HideFromAddressLists items, that would be great.

@bazookadaver could you already test mag210's link and check if it works? thanks.

@bazookadaver, you don't need to modify the webpart, if you follow the MS guide through you will hide that user from all of O365 including any SP search. We use it to hide our admin accounts which we don't want to appear in any 365 search, including delve. As I've said the other approach is to create a custom result source in SP and point the webpart at this. However, if you do this, it will only be the webpart that hides the accounts. I think a more holistic solution (depending on your requirements) is to exclude the accounts you want from 365 as a whole? Note this solution only works with synced AD accounts.

I haven't been able to test yet, but will let you know. Appreciate the feedback.

I have this same issue where I have ex-employees showing up as well as admin/service accounts. I actually took the People Directory web part out of the solution and packaged it into its own solution so I can individually add it as required.

Anyways, for this, you can update the REST query in the PeopleDirectory.tsx. You can add a refinementfilter to refine the results you return from the query.

There is a flag in Exchange (msExchHideFromAddressLists ) which you can set in Exchange so users do not show up in the Global Address List..

This flag syncs with the User Profiles on SharePoint with the property SPS-HideFromAddressLists. You can add this in flag in the Refinement Filter for the REST api call. For example:

&refinementfilters='and(WorkEmail:("*@contoso.com"),SPS-HideFromAddressLists:(0))'

So I only search for accounts that have a work email address and the flag is not set.

That's a good solution for this webpart, its' just a shame that we can't amend the modern search query for the whole of 365, as your users will still show up in searches in portal.office.com and SP org searches. Hiding from the address list is a good partial solution but only works for synced on prem accounts

One of the issues I am having is to filter out Service accounts, or accounts that dont have anything in one of the attributes (eg Job Title is null). I tried doing a compound refinementFilter

refinementfilters=%27and(and(WorkEmail:("*@contoso*"),SPS-HideFromAddressLists:(0)),JobTitle:not(""))%27

But I am not sure if we can use the query to filter out Null values. I have spent quite a bit of time searching online to see if FQL allowed for this, but I cannot seem to find an answer. Does anyone know if something like this is possible?

You unfortunately can't "filter" out null values, because you can't search against something that doesn't exist. The only way you'd do that is to search for items that do contain values using a bunch of concatenated ORs in the search query.

You unfortunately can't "filter" out null values, because you can't search against something that doesn't exist. The only way you'd do that is to search for items that _do_ contain values using a bunch of concatenated ORs in the search query.

Ahh yes. I did come across that as a suggested solution. I think I can do some array manipulation after getting the result set. It wont be as efficient as filtering out in the query itself, but we have a small enough dataset so it should not cause as much overhead..

I would like to filter out B2B user accounts

I would like to filter out B2B user accounts

I managed to achieve this, albeit not using the search query. I had to filter my results array and remove any entries that didnt have a "job title".

people = people.filter(function(Person){ if(Person.jobTitle) return Person; });

That worked for me.

It looks like this question may have been answered.

Is it okay to close this ticket, or are you still looking for feedback?

Closing issue as "answered". If you encounter similar issue(s), please open up a NEW issue. Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonasbjor picture jonasbjor  路  8Comments

karigeir picture karigeir  路  5Comments

ShowMeTheGita picture ShowMeTheGita  路  7Comments

tchagan picture tchagan  路  4Comments

VesaJuvonen picture VesaJuvonen  路  5Comments