Home > Software engineering >  How to find if a key is present in an array - Typescript - Microsoft flows
How to find if a key is present in an array - Typescript - Microsoft flows

Time:04-28

I have multiple users and I want to filter them based on their office location I get the location with a flow "Search for users (V2)" which returns an array of information about each user that includes ID, Email, Country .. etc

Some of them do not have all of these info, in my case they don't (Office location) at all, which will cause the flow to show an error

This is my flow

Flow

This is the result result

and error condition error

Any thoughts? Thank you!

CodePudding user response:

I'm a little confused as to why you're using a Condition action with a first() function straight after your Search for users call, that doesn't match the description on your issue.

If it were me, I'd be using the Filter array action to get that list broken down as need be and then you can work with it from there.

In my test below, you can see that I'm filtering based on the term Head Office in the returned array.

Flow

I have 3 users that it pulls back and two have the OfficeLocation property set to Head Office.

Before Filter

[
  {
    "Id": "c9692d85-ae00-470f-8544-4ded06082d59",
    "AccountEnabled": true,
    "BusinessPhones": [],
    "DisplayName": "Automation",
    "Mail": "[email protected]",
    "MailNickname": "automation",
    "OfficeLocation": "Head Office",
    "UserPrincipalName": "[email protected]"
  },
  {
    "Id": "8ddf4a13-fa28-4c76-8a79-dfcc680b57b9",
    "AccountEnabled": true,
    "BusinessPhones": [
      "4251001000"
    ],
    "DisplayName": "Joe Bloggs",
    "GivenName": "Joe",
    "Mail": "[email protected]",
    "MailNickname": "joe.bloggs",
    "Surname": "Bloggs",
    "UserPrincipalName": "[email protected]"
  },
  {
    "Id": "9d903297-2777-48d8-beb3-95e4e9ad2851",
    "AccountEnabled": true,
    "BusinessPhones": [],
    "DisplayName": "Jane Doe",
    "GivenName": "Jane",
    "Mail": "[email protected]",
    "MailNickname": "jane.doe",
    "OfficeLocation": "Head Office",
    "Surname": "Doe",
    "UserPrincipalName": "[email protected]"
  }
]

After Filter

[
  {
    "Id": "c9692d85-ae00-470f-8544-4ded06082d59",
    "AccountEnabled": true,
    "BusinessPhones": [],
    "DisplayName": "Automation",
    "Mail": "[email protected]",
    "MailNickname": "automation",
    "OfficeLocation": "Head Office",
    "UserPrincipalName": "[email protected]"
  },
  {
    "Id": "9d903297-2777-48d8-beb3-95e4e9ad2851",
    "AccountEnabled": true,
    "BusinessPhones": [],
    "DisplayName": "Jane Doe",
    "GivenName": "Jane",
    "Mail": "[email protected]",
    "MailNickname": "jane.dow",
    "OfficeLocation": "Head Office",
    "Surname": "Doe",
    "UserPrincipalName": "[email protected]"
  }
]
  • Related