cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Phineas
Post Prodigy
Post Prodigy

Filtering Active Directory Contacts

I have a screen with Gallery1.

 

Gallery1 - Items is doing a top 100 search of Office 365 Users.

 

This search goes across multiple entities. This effort only requires the users to see contact information for employees in the same entity in-which they reside.

 

Let's use the National Football League as an example. The below is pulling at all contacts in the NFL system; however, in Gallery1 we only want to see the emails for members in the 'NFC West'; how do I make that happen?

 

I currently have the following in the Items of the Gallery:

 

     If(!IsBlank(Trim(TextSearchBox1.Text)), Office365Users,SearchUser({searchTerm: Trim(TextSearchBox1.Text), top: 100}))

1 ACCEPTED SOLUTION

Accepted Solutions
StalinPonnusamy
Super User
Super User

Hi @Phineas 

 

For better performance, We can store user email on the variable when the app starts and use the variable instead of accessing User().Email many times.

Set App OnStart

Set(UserEmail, User().Email)

 

and use the variable

With(
    {
        _SearchUser: Office365Users.SearchUser(
            {
                searchTerm: If(
                    !IsBlank(Trim(TextInput3.Text)),
                    Trim(TextInput3.Text),
                    ""
                ),
                top: 100
            }
        )
    },
    Filter(
        _SearchUser,
                Last(
            Split(
                UserEmail,
                "@"
            )
        ).Result in Mail
    )
)

 

View solution in original post

6 REPLIES 6
Ashwin7104
Super User
Super User

@Phineas - If 'NFC West' is stored in one of the user object parameter of the Office365 users connector, add a filter condition to your code to filter members using that parameter. In the example below, I'm filtering users by Department rather than the full AD.

 

Filter(Office365Users.SearchUser({ searchTerm: TextInput2.Text, top: 500 }),Department= "Technology")

 

https://docs.microsoft.com/en-us/connectors/office365users/#get-user-profile-(v2) 

Sir, thank you for you reply.

 

Unfortunately, "NFC West" is not stored.

 

I hoping to be able to isolate the members by their email addresses.

 

Assuming the entity as a whole have four divisions and each employees internal email was based on their division?

 

For example: The company is the "The Great Briar Patch"; the North division lead is Peter Rabbit at Peter_Rabbit@GPBNorth.com; however, the South division lead is Bugs Bunny @ Bugs_Bunny@GBPSouth.com

 

In my search as the administrator at GBP I am creating a Power App for the Sout division employees only, is there a way to rewrite the below to filter the active directory to return only the contact information for members from the South division to choose from rather than all members?

 

       If(!IsBlank(Trim(TextSearchBox1.Text)), Office365Users,SearchUser({searchTerm: Trim(TextSearchBox1.Text),

       top: 100}))

StalinPonnusamy
Super User
Super User

Hi @Phineas 

 

The below code search user and withing the domain based on the email like GPBNorth or South

With(
    {
        _SearchUser: Office365Users.SearchUser(
            {
                searchTerm: If(
                    !IsBlank(Trim(TextInput3.Text)),
                    Trim(TextInput3.Text),
                    ""
                ),
                top: 100
            }
        )
    },
    Filter(
        _SearchUser,
                Last(
            Split(
                User().Email,
                "@"
            )
        ).Result in Mail
    )
)

 

StalinPonnusamy
Super User
Super User

Hi @Phineas 

 

For better performance, We can store user email on the variable when the app starts and use the variable instead of accessing User().Email many times.

Set App OnStart

Set(UserEmail, User().Email)

 

and use the variable

With(
    {
        _SearchUser: Office365Users.SearchUser(
            {
                searchTerm: If(
                    !IsBlank(Trim(TextInput3.Text)),
                    Trim(TextInput3.Text),
                    ""
                ),
                top: 100
            }
        )
    },
    Filter(
        _SearchUser,
                Last(
            Split(
                UserEmail,
                "@"
            )
        ).Result in Mail
    )
)

 

It took everything except the 'UserEmail' at the end. I changed that to 'Mail', the errors went away.

However, this still returns ALL names and emails, not just the ones I seeks.

Old eyes!

 

I finally typed it correctly.

 

It works, Thank you!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,350)