0

I have a power automate flow where I have an array of objects which contains email address as a filed. I have another array that just has email addresses. I want to filter array of objects based on the email present in the other array. I am a newbie to power automate and any help in solving this would be highly appreciated.

Array of objects:

[
    {
      "@odata.etag": "",
      "ItemInternalId": "a23f2019-2b33-41af-a741-7faedeed9e0f",
      "First Name": "John",
      "Last Name": "Wick",
      "Email Address": "[email protected]",
      "Manager Email Address": "[email protected]",
      "Manager First Name": "John",
      "Manager Last Name": "Wick"
    },
    {
      "@odata.etag": "",
      "ItemInternalId": "6fc4cc1b-13e8-47c3-9fca-09872fe758ae",
      "First Name": "John2",
      "Last Name": "Wick2",
      "Email Address": "[email protected]",
      "Manager Email Address": "[email protected]",
      "Manager First Name": "John2",
      "Manager Last Name": "Wick2"
    }
  ]

Array of email addresses:

  [
    "[email protected]",
    "[email protected]",
    "[email protected]",
    "[email protected]"
  ]

So, the result I am looking for is an array of objects that contains the matching object (in this case):

[
    {
      "@odata.etag": "",
      "ItemInternalId": "a23f2019-2b33-41af-a741-7faedeed9e0f",
      "First Name": "John",
      "Last Name": "Wick",
      "Email Address": "[email protected]",
      "Manager Email Address": "[email protected]",
      "Manager First Name": "Test",
      "Manager Last Name": "Surname"
    }
]
3
  • You open to a third party connector? Commented Jun 21, 2023 at 2:24
  • @Skin sure. I can try it out. Commented Jun 21, 2023 at 2:57
  • I'll give you an answer then. Commented Jun 21, 2023 at 3:08

1 Answer 1

0

I think you could achieve it quite easily using the Advanced Data Operations connector.

https://www.statesolutions.com.au/

https://learn.microsoft.com/en-us/connectors/advanceddataoperatio/

However, the most annoying part about the dataset you've provided is that the email addresses used to filter the main array is more of a primitive type array where as it needs to be an object based array.

Either way, I'll explain the flow I have tested with.

Flow

Step 1/2.

Both of these steps are merely variables of type Array that hold the values you specified in your question, noting that the @ at the start of the first properties have been removed because PA doesn't like them.

Step 3.

This is a very small C# script that turns your primitive array into an object array.

C# Script

Script

var result = new List<ReturnData>();

foreach (var item in parameters.ArrayToTransform)
  result.Add(new ReturnData() { EmailAddress = item });

return result;

Class Definitions

public class ReturnData
{
    [JsonProperty("Manager Email Address")]
    public string EmailAddress { get; set; }
}

Parameters

{
  "ArrayToTransform": @{variables('Email Address Array')}
}

This is the resulting output and it's this structure that we need for the final step ...

{
  "returnValue": [
    {
      "Manager Email Address": "[email protected]"
    },
    {
      "Manager Email Address": "[email protected]"
    },
    {
      "Manager Email Address": "[email protected]"
    },
    {
      "Manager Email Address": "[email protected]"
    }
  ],
  "log": []
}

Step 4.

This step is a little superfluous but am doing it anyway. I'm basically taking the output from the C# Script operation and setting the Email Address Array value with it.

Set Variable

Expression = outputs('C#_Script_Execute')?['body']['returnValue']

Step 5.

Now with the two datasets, you can perform an inner join and remove the data that doesn't match up to a supplied email address.

Join

Take note, you want to join on the Manager Email Address (I made an assumption here given it matches to an email in the list) and the fields you want to return are only those from the Array To Filter dataset.

Join Fields = [ "Manager Email Address" ]

Fields = [ "+FieldName(ArrayToFilter.%)" ]

Result

Only the one result is returned because that's the only one that married up to an entry in the email addresses list.

[
  {
    "odata.etag": "",
    "ItemInternalId": "a23f2019-2b33-41af-a741-7faedeed9e0f",
    "First Name": "John",
    "Last Name": "Wick",
    "Email Address": "[email protected]",
    "Manager Email Address": "[email protected]",
    "Manager First Name": "John",
    "Manager Last Name": "Wick"
  }
]

Join Result

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.