cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
jkeckard007
Level: Powered On

Get Items and then Send Email

All 

I am new to flow so here goes,

I have a Recurrence Flow that I want to query a SharePoint list and if the PO column is New then send an email to a group of people.   I get the recurrence set up but I am not understanding in the Get Items piece how to get the results of that action.

I basically want a count of items that have a PO of New If >0 send an email.  If not, do nothing.

Can someone help?

Thanks

Jennifer

1 ACCEPTED SOLUTION

Accepted Solutions
Dual Super User
Dual Super User

Re: Get Items and then Send Email

Hi again

From the screenshot you shared, I would keep "Get items", "Filter Array". I would also remove both "Apply to each" and the compose action block.

Once these are removed, I would add

Next I would add a Condition, and use the following expression:

@equals(length(body('Filter_array'),0)

On the "True" branch I would add a Terminate action block. On the "False" branch I would add nothing.

Then, outside the condition, I would add a Select action Block (you can see more information here:

https://docs.microsoft.com/en-us/flow/data-operations#use-the-select-action )

You need to add Filter Array output as the input for this new Select action block. If you follow the instructions from the link above, you will see Select allows you to choose which columns from the filtered items you want to keep.

Then I would follow @v-yamao-msft suggestion to include "Create HTML table" action block, adding the Select Action Block output as the input for this new "Create HTML table" action block. I would finally add "Send an email" following @v-yamao-msft suggestion.

Please note Flow allows to implement an idea in different ways. From the screenshot you shared it seems you haven't followed @v-yamao-msftsuggestions, but tried a different way instead. But I guess the double Apply to Each in your Flow screenshot is making the Filter array useless; and for some reason the Compose action block is not getting the value of the expressions, but the expressions in a literal way.

Hope this helps

 





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





View solution in original post

16 REPLIES 16
Community Support Team
Community Support Team

Re: Get Items and then Send Email

Hi @jkeckard007,

 

You said that “if the PO column is New”, do you mean that the created time of this column is equal to today?


After the action Get items, you need to add a Condition or an action Filter array to filter the items that are new.


Please take the following screenshot for a reference.


In this flow, I am using the action “Filter array”. The code is:

@equals(formatDateTime(item()?['Created'], 'yyyy-MM-dd'), formatDateTime(utcnow(), 'yyyy-MM-dd'))


Then I use Create HTML table so that I can send the items at a time.

3.PNG

 

Please take the following docs for a reference:
https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language
https://flow.microsoft.com/en-us/blog/html-tables-csvs-computer-vision/


Best regards,
Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
jkeckard007
Level: Powered On

Re: Get Items and then Send Email

New is the default value for the field. The parts department could get the request and fill it on the same day.  They change the PO field to a PO number instead of New.  I think I can modify the information you sent and possibly make this work.  I will attempt and let you know.  Thank you

Jennifer 

jkeckard007
Level: Powered On

Re: Get Items and then Send Email

All,

with help I have the Get Items filtering but what I want to do is if there are no items with PO eq New then do nothing if there is one then send an email. The issue is that it is the expression which is @equals(item()?['PO'],'New')  it is returning false  but it is in fact true.  I don't want to do a: for each, I don't think because I only want to send one email not multiple.  Any help would be great!

Dual Super User
Dual Super User

Re: Get Items and then Send Email

Hi

Are you using the expression inside an Filter Array action Block? Inside a Condition in an Apply To Each? or in the ODATA Filter input at the Get Items action block?

I mean @equals(item()?['PO'],'New')

If you are using it in any of the two options above, it should work unless the content of 'PO' returned is different. Moreover, ff you are using an ApplyToEach+Condition, you can inspect the content by adding a Compose action Block with the following expression

item()?['PO']

just before the Condition.

Then you can execute the flow, and verify details in Run History

Hope this helps

 

 





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





jkeckard007
Level: Powered On

Re: Get Items and then Send Email

Currently I have  Sorry can't seem to post picture but the item returns as false and there is a New item in the list the get item action returns both one that is set to New and one that is not.

I tried to filter  the array  but not sure how to do a condition on that.  Sorry really new to Flow and trying to figure this out as this is the way of the futuren with workflows.

Get Item

Then Condition as stated previously then

If Yes Send email

If No nothing

Dual Super User
Dual Super User

Re: Get Items and then Send Email

Hi again

If you are using "SP Get Item" it is because you already have the Item ID and add it as input, so you get back an object with all the target item related info.

If so, you do not need to filter, you got the item you were looking for.

 

If you are using "SP Get Items" you do not need to add as input the Item ID, since you are getting all items in the list as an array of objects. Once you get this array, you can filter it following the different strategies I commented on my initial post

 

There is an excellent tutorial on how to combine "Get items" and "Filter Array" published on Microsoft Flow official https://flow.microsoft.com/en-us/blog/email-digest-date-manipulations/

Hope this helps





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





jkeckard007
Level: Powered On

Re: Get Items and then Send Email

OK am really slow here because I am folling the example and I can not get the flow to save it says

' cannot reference action 'Compose'. The action 'Compose' is nested in a foreach scope of multiple levels. Referencing repetition actions from outside the scope is supported only 

When I am in the email section and I do the join it says to do.

Also in this example it appears the email will send even if there is nothing in the list to send.  I want the email not to send if the array is empty.

 

Dual Super User
Dual Super User

Re: Get Items and then Send Email

Hi again

Can you share a screenshot of your flow?

 





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





jkeckard007
Level: Powered On

Re: Get Items and then Send Email

image.png

Dual Super User
Dual Super User

Re: Get Items and then Send Email

Hi

Was the inner Apply to Each added automatically? If you added it manually, can you remove it?

Can you also share the expressions you are using in your Compose Block ?

Can you also share the join expression in the email body?

 

Please note the first Apply to each is applying to the "Filter array" result, while the second Apply to Each is applying to the "Get items" result. So I guess if you change the two expressions inside the Compose Block and replace them by item()?['NotSureWhatsTheNameOfTheColumnYouAddedHere']

Hope this helps





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





jkeckard007
Level: Powered On

Re: Get Items and then Send Email

OK the second for each was due to the instructions saying to do items('Apply_to_each')?['Title'] in the html build.

I changed this to <tr><td>item()?['Description']</td><td>item()?['Order Qty']</td></tr>

The email fired but no table was in there

the body says

<table>Join(actionOutputs('Compose'),'.')</table>

But the email says

item()?['Description']

item()?['Order Qty']

This is fustrating thank you for your help on all this.  I still don't know how to get the item to not fire an email if there are no New parts but one thing at a time 🙂

Dual Super User
Dual Super User

Re: Get Items and then Send Email

Hi again

 

Let's try to summarize.

You want to grab the items in the Sharepoint List matching a certain criteria (the Filter Array).

The criteria you have defined in the Filter Array is the following:

@equals(item()?['PO'],'New')

 

Then, you want to create an HTML table with two columns taken from the SP List structure: "Description" and "Order Qty", and as many rows as the items that matched the criteria in the Filter Array.

 

Finally you want to send a single email with the table result.

 

The Filter is not working as you expected, so no matter the content of the "PO" column in Sharepoint is, all the items are included in the HTML table.

Also, the table is finally showing the same info per item:

item()?['Description']       item()?['Order Qty']

 

Is the summary right?

 

 

 




If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





jkeckard007
Level: Powered On

Re: Get Items and then Send Email

as you outline it is correct except for one thing.  If there is no items in the filter array portion do not send an email at all.

 

Dual Super User
Dual Super User

Re: Get Items and then Send Email

Hi again

From the screenshot you shared, I would keep "Get items", "Filter Array". I would also remove both "Apply to each" and the compose action block.

Once these are removed, I would add

Next I would add a Condition, and use the following expression:

@equals(length(body('Filter_array'),0)

On the "True" branch I would add a Terminate action block. On the "False" branch I would add nothing.

Then, outside the condition, I would add a Select action Block (you can see more information here:

https://docs.microsoft.com/en-us/flow/data-operations#use-the-select-action )

You need to add Filter Array output as the input for this new Select action block. If you follow the instructions from the link above, you will see Select allows you to choose which columns from the filtered items you want to keep.

Then I would follow @v-yamao-msft suggestion to include "Create HTML table" action block, adding the Select Action Block output as the input for this new "Create HTML table" action block. I would finally add "Send an email" following @v-yamao-msft suggestion.

Please note Flow allows to implement an idea in different ways. From the screenshot you shared it seems you haven't followed @v-yamao-msftsuggestions, but tried a different way instead. But I guess the double Apply to Each in your Flow screenshot is making the Filter array useless; and for some reason the Compose action block is not getting the value of the expressions, but the expressions in a literal way.

Hope this helps

 





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





View solution in original post

Dual Super User
Dual Super User

Re: Get Items and then Send Email

Hi again

I've found another excellent example on how to combine Get Items + Filter Array + Select+ Create HTML Table + Send an email via @v-xida-msft here:

 

https://powerusers.microsoft.com/t5/Building-Flows/Monthly-email-with-info-about-new-items-in-SP-lis...

 

Happy Flowing!

 





If anybody solved your question, remember to mark its post as a solution!

Proud to be a Flownaut!





jkeckard007
Level: Powered On

Re: Get Items and then Send Email

The below is giving me an error @equals(length(body('Filter_array'),0)

The template validation failed: 'The template action 'Condition' at line '1' and column '1736' is not valid: "Unable to parse template language expression 'equals(length(body('Filter_array'),0)': expected token 'RightParenthesis' and actual 'EndOfData'.".'.

 

I figured it out though it is 

@equals(length(body('Filter_array')),0)

 

I just made the email send with a link to the sharepoint list I did not need the html stuff at this time

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 373 members 6,534 guests
Please welcome our newest community members: