Skip to main content

Notifications

Power Automate - General Discussion
Answered

Compare Two Array for Each Unique ID and Send Email

(0) ShareShare
ReportReport
Posted on by 32
I have a SharePoint List that logs a user's completion on a specific training:
Odie_0-1644838668808.png

 

This is what I've done so far:

Odie_3-1644838792638.png

 

I have three branches:

Branch 1 - Get SharePoint list from this image:

Odie_0-1644838668808.png

and set it to an array (varMembers_Completed [Title, EID]).

Branch 2 - Get all members from a SharePoint list and set it to an array (varMembers [EID]).

Branch 3 - Get Training List.

--------------------------------------------------------
I need help for the next step as I would like to compare the three branches.

 

For each title, I would like to compare varMembers and varMembers_Completed.

 

If an EID matched from varMembers and varMembers_Completed that means that he/she has completed the training, no action needed.

Else, I would like to place it on a list.

 

So the overall output, for example on an email should look like this:

 

Training Title: Test

[Names of those who are not on the list yet]

 

Training Title: Test2

[Names of those who are not on the list yet]

  • Odie Profile Picture
    Odie 32 on at
    Re: Compare Two Array for Each Unique ID and Send Email

    My bad. I've joined it from the FilterWhoDidntAttend. It should be SelectEIDFromDidntAttend.

     

    Thanks for such huge help @DamoBird365

  • DamoBird365 Profile Picture
    DamoBird365 8,942 on at
    Re: Compare Two Array for Each Unique ID and Send Email

    Hi @Odie 

     

    No idea where that has come from.  If you are not doing any further transformation on the select array, I would use the select array.  Take a look at the history output of the select array - you will see the output.  I cannot imagine that the foreach is actually doing anything to it.

     

    Damien

  • Odie Profile Picture
    Odie 32 on at
    Re: Compare Two Array for Each Unique ID and Send Email

    As for the union, the formula is: 

    union(variables('varMembers_Completed'), createArray(item()))
    Odie_1-1644943158650.png

     


     

  • Odie Profile Picture
    Odie 32 on at
    Re: Compare Two Array for Each Unique ID and Send Email

    Seems that I have to update my flow as it would be running on a huge data. The forEach is really taking time.

     

    No update is happening on the flow, just an email that I have to send for the trainings.

     

    Thanks for the tip!

  • Odie Profile Picture
    Odie 32 on at
    Re: Compare Two Array for Each Unique ID and Send Email

    Hi @DamoBird365  - It seems that the output from the compose returns an object.

     

    The output from the SelectFromDidntAttend is as follows:

    [
     "User1",
     "User2",
     "User3"
    ]

     

    1.png

    It seems that the "EID" key is also being appended to the compose. What can I do to extract only the value?

  • DamoBird365 Profile Picture
    DamoBird365 8,942 on at
    Re: Compare Two Array for Each Unique ID and Send Email

    @Odie 

     

    Mmmm...  Select is an array and you have defined the two key/value pairs.  You only need an array in a variable action if you want to update it, otherwise a select or compose will serve the purpose of a read only variable.

     

    What's happening in union? 

     

    Just wondering if you need all of that extra stuff and make your flow even more efficient.

     

    Damien

  • Odie Profile Picture
    Odie 32 on at
    Re: Compare Two Array for Each Unique ID and Send Email

    @DamoBird365 - I basically have 3 SharePoint list for the three branches.

     

    Mapped the list to a select, then used a forEach to create an array and assign it on my array variable.

     

    Odie_0-1644940687127.png

     

  • DamoBird365 Profile Picture
    DamoBird365 8,942 on at
    Re: Compare Two Array for Each Unique ID and Send Email

    @Odie p.s. what is in your for each?  Just being nosey.

     

    Damien

  • DamoBird365 Profile Picture
    DamoBird365 8,942 on at
    Re: Compare Two Array for Each Unique ID and Send Email

    Hi @Odie 

     

    If you add a select and compose to your apply to each and then two composes outside of your apply to each like so, this will bring everything together for 1 email.  I am assuming it's 1 email, rather than an email per course.

     

    Select: 

    item()?['EID']

    Compose : 

    Training Title items('Apply_to_each')?['Training Title']

    Join(body('SelectEIDFromDidntAttend'),', ')

     

    ComposeReturnLine 

    Literally slap a return key in there 👍

     

    ComposeString: 

    join(outputs('ComposeStringObject'),outputs('ComposeReturnLine'))

     

    DamoBird365_2-1644938451171.png

     

    Output is as follows:

     

    DamoBird365_1-1644938189994.png

    And users will be comma separated if more than 1.

     

    I'll probably do a wee video on this concept as it is a really good use case.  Thanks for the challenge 😉  

     

    Please consider accepting my answer as a solution if it helps to solve your problem.

    Cheers
    Damien

    Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts, or take a look at my website. Thanks

     

  • Odie Profile Picture
    Odie 32 on at
    Re: Compare Two Array for Each Unique ID and Send Email

    Thanks! It worked perfect. Can you give me an idea on how to achieve this output:

     

    Training Title: Test

    [Names of those who are not on the list yet]

     

    Training Title: Test2

    [Names of those who are not on the list yet]

     

    ...

     

    I would like to use the output and send it using Outlook Email.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,636

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,942

Leaderboard