cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
vipfafen
Frequent Visitor

Fitler array - multiple conditions.

Hi there,

 

my "multiple conditions - filter array" does not work properly.

 

1.

First single condition works like a charm - search for users (V2)

- @not(endswith(item()?['UserPrincipalName'], '@<DOMAINNAME>'))

 

Result: exclude all internal user

 

2. 

second multiple condition does not run against an error, but does not work properly either - 

i try this bouth:

@And(not(endswith(item()?['UserPrincipalName'], '@<DOMAINNAME>')),not(contains(item()?['UserPrincipalName'], 'EXT')))

- @And(not(endswith(item()?['UserPrincipalName'], '@<DOMAINNAME>')),and(not(contains(item()?['UserPrincipalName'], 'EXT'))))

 

i already try with lower case, even with '#'

 

Desired result: exclude all internal user, except the UPN includes a 'EXT'

 

 

Filter arry inputs:

{
    "Id""*",
    "AccountEnabled"true,
    "BusinessPhones": [],
    "DisplayName""John, Doe",
    "Mail""john.Doe@<DOMAINNAME>",
    "MailNickname""john.Doe_<DOMAINNAME>#EXT#",
    "UserPrincipalName""john.Doe#EXT#@<DOMAINNAME>"
  },
 
Filter arry outputs:
john is missing...
 
What am I doing wrong?
 
I thank you in advance
1 ACCEPTED SOLUTION

Accepted Solutions

ok, i found a way,

 

in the past i tried to use a multiple "@and" condtion, to keep this kind of output:

 

 

"id": ...
"Mail": ...
"UserPrincipalName": "john.Doe#EXT#<@Domainname>"

 

 

For whatever reason, despite the following conditions, users with "ext" and "<@Domainnam>
discarded.

 

 

(
    not(endswith(item()?['UserPrincipalName'], '@<Domainname>')),
    not(contains(item()?['UserPrincipalName'], 'EXT'))
    )

 

 

 

This one workx:

Screenshot 2020-12-29 151713.jpg

 

I add aparallel brunch:

1. array Filter: @not(endswith(item()?['UserPrincipalName'], '<@Domainname>'))

2. array Filter: @endswith(item()?['UserPrincipalName'], '#EXT#<Domainname>')

 

... to intercept the faulty filters

 

3. Comose: 

union(body('Filter_array_-_IncludeInternalUserEXT'),body('Filter_array_-_RemoveinternalUser'))

 

To merge both array filter outputs

 

Although it takes a couple of days, but... I'm new to the topic


Thanks to all involved

View solution in original post

7 REPLIES 7
tom_riha
Super User II
Super User II

Hello @vipfafen ,

I'd break down the condition into single steps:

@And(
    not(endswith(item()?['UserPrincipalName'], '@<DOMAINNAME>')),
    not(contains(item()?['UserPrincipalName'], 'EXT'))
)

for "UserPrincipalName": "john.Doe#EXT#@<DOMAINNAME>" it will go like this:
@And(
    not(TRUE),
    not(TRUE)
)

@And(
    FALSE,
    FALSE
)

= FALSE

If I understand it correctly, you want to keep the users that contain EXT and users in different domain. Then the condition should probably go as below. 

@Or(
    not(endswith(item()?['UserPrincipalName'], '@<DOMAINNAME>')),
    contains(item()?['UserPrincipalName'], 'EXT')
)

for "UserPrincipalName": "john.Doe#EXT#@<DOMAINNAME>":
@Or(
    not(TRUE),
    TRUE
)

= TRUE (keep the user)

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

@tom_riha 

thank you for your replay.

 

We have around 500 users in AzureAD. I would like to exclude all internal users and make a compilation of all external users. the external users only differ via the EXT in the UPN. The domain is identical for internal and external, we still have other domains that should be excluded from the search. So I would like to exclude all domain users, unless they have the "EXT" in UPN, so thats way i have to use "and", to catch both conditions.

 

Still the same, john.doe comes with the input, but missing on output, i go mad...

 

i tried this one:

 

@And(
    not(endswith(item()?['UserPrincipalName'], '@<DOMAINNAME>')),
    not(contains(item()?['UserPrincipalName'], 'EXT'))
)

 

vipfafen
Frequent Visitor

I have tried the following, without success. John Doe comes with the input, but still missing on the output. 

 

@And(
    not(endswith(item()?['UserPrincipalName'], '@<DOMAINNAME>')),
    not(contains(item()?['UserPrincipalName'], 'EXT'))
    )

 

both conditions have to be true, to exclude internal users

vipfafen
Frequent Visitor

Hi all,

I found the bug... sitting in front of the screen.

In the past we created users manually. There are differences in the spelling of domainnames.

for example:

- Domain-Name

- domain-name

and so on...

 

so i have to put a step between "get all users" and "filter arry". 

if I understand correctly, I have to run a "toLower" function after the user output.

Screenshot 2020-12-27 180031.jpg

I would be happy about approaches, I'm still quite unsure about "variable" and "data operation" actions

 

regards

Hello @vipfafen ,

if you got the filter working, you can use the toLower() expression directly in the filter, just put the UserPrincipalName dynamic content inside.

Example:

@And(
    not(endswith(toLower(item()?['UserPrincipalName']), '@<domainname>')),
    not(contains(toLower(item()?['UserPrincipalName']), 'ext'))
    )

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]
vipfafen
Frequent Visitor

Hi @tom_riha ,

 

thank you for your approaches, i really appreciate it.

I found out that it's not a case sensitive issue.

 

It doesn't matter if I use either of the following expressions, the output in both cases is 285 (User):

 

 

@not(endswith(item()?['UserPrincipalName'], '@<domainname>'))
@not(endswith(toLower(item()?['UserPrincipalName']), '@<domainname>'))

 

when I do your suggested expression, i get a output of 243 (User). This isn't right, it have to be more then 285 User. 

 

Example:

@and(
    not(endswith(toLower(item()?['UserPrincipalName']), '@<domainname>')),
    not(contains(toLower(item()?['UserPrincipalName']), 'ext'))
    )

 

Therefore, both cases must apply to the "and" condition. exclude "@domainname" if "EXT" not appears in it.

 

Dividing the filters, passing them into two "arrays" and then merging them seems to be too much effort.

I have no other ideas, the "and" condition doesn't seem to work properly or I didn't understand it.

ok, i found a way,

 

in the past i tried to use a multiple "@and" condtion, to keep this kind of output:

 

 

"id": ...
"Mail": ...
"UserPrincipalName": "john.Doe#EXT#<@Domainname>"

 

 

For whatever reason, despite the following conditions, users with "ext" and "<@Domainnam>
discarded.

 

 

(
    not(endswith(item()?['UserPrincipalName'], '@<Domainname>')),
    not(contains(item()?['UserPrincipalName'], 'EXT'))
    )

 

 

 

This one workx:

Screenshot 2020-12-29 151713.jpg

 

I add aparallel brunch:

1. array Filter: @not(endswith(item()?['UserPrincipalName'], '<@Domainname>'))

2. array Filter: @endswith(item()?['UserPrincipalName'], '#EXT#<Domainname>')

 

... to intercept the faulty filters

 

3. Comose: 

union(body('Filter_array_-_IncludeInternalUserEXT'),body('Filter_array_-_RemoveinternalUser'))

 

To merge both array filter outputs

 

Although it takes a couple of days, but... I'm new to the topic


Thanks to all involved

View solution in original post

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MSFTBizAppsLaunchEvent

Experience what’s next for Power Virtual Agents

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Users online (52,548)