cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mar01
Helper I
Helper I

Automate flow that filters list items and count them based on meta content from new added item

Hi all, 

 

I want to make an automated flow that counts the existing items in a list based on the metadata from a new added item.

For instance a list has the following items:

TitleObservationProgram
1_Bug_WindowsBugWindows
1_Calculation_MathcadCalculationMathcad
1_Layout_PythonLayoutPython
2_Bug_WindowsBugWindows

 

Now I add a new item to the list with 'Title' = Errror, 'Observation' = Bug, 'Program' = Windows.

 

The automate flow has to go through the existing items and return the number of items that match with the metadata (Observation and Software) of the new added item. In this example it should return item 1 and item 4.

It then should count the number of items including the new added item (e.g. 3). 

 

Reason is that I want to force the title to be unigue to the entry (see example). The title is now something which it to be included manually but, with every new added item, one has to check which follow number is to be used. 

 

How can I achieve this?

 

I already managed to get title renaming working for a library, with great help from @efialttes (see: Library count) but this does not seem to work the same for lists.

 

Your help is greatly appreciated.

 

Regards,

Martin

 

11 REPLIES 11
Mira_Ghaly
Dual Super User
Dual Super User

Hi @mar01 

Please try the below; Get Items with Filter Query

Mira_Ghaly_0-1600757183593.png

Then use the expression below in the compose action to get the number of items:

length(outputs('Get_items')?['body/value'])
 
Hope this helps!

 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here

@Mira_Ghaly 

 

That does not seem to work nor do I understand what you exactly mean. 

It needs to filter the items from the list based on the item metadata that is changed or newly added.

 

I have this:

Capture 8.JPG

 

 

@mar01 

can you Construct the filter Query? as in the my previous screen shot using the variables you have constructed?

 

Observation eq ObservationID and Program eq  SoftwareID

 

 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here

@Mira_Ghaly 

 

That does not work either assuming that Program == Software:

Observation eq ObservationID and Software eq  SoftwareID

 

I get an error which seems logical as the column is called 'Observation':

Column 'ObservationID' does not exist. It may have been deleted by another user.
clientRequestId: 8b09f45d-0eca-4849-b8c3-317134a7604f
serviceRequestId: 8b09f45d-0eca-4849-b8c3-317134a7604f

 

I tried the following as filter query:

  • Observation eq ObservationID and Software eq SoftwareID
  • ['body/Observation/value'] eq ObservationID and ['body/Software/value'] eq SoftwareID
  • ['body/Observation'] eq ObservationID and ['body/Software'] eq SoftwareID

The variables ObservationID and SoftwareID are taken from the changed/added item (e.g. triggerOutputs()?['body/Observation/Value']

 

What am I doing wrong?

 

@mar01 

In the left hand side for your expression use the sharepoint column name which i suppose equals Observation

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here

@Mira_Ghaly 

 

I understand that the left hand side is the column name but, for some reason that does not work whereas they are as they are called now. Is there a different way to get the information without using the filter query in 'Get Items'?

@mar01 

If it does not work then you need to check the column name in your sharepoint list to make sure it is the same spelling and case sensitive.

I can't think of a way other than the GetItems Filter Query.

 

 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here

@Mira_Ghaly 

 

It seems that, if you use a variable in your filter query, you need to include the " ' " too.

The attempts were:

1. Observation eq @{variables('ObservationID')} and Software eq @{variables('SoftwareID')} > fail

2. (Observation eq @{variables('ObservationID')}) and (Software eq @{variables('SoftwareID')}) > fail

3. (Observation eq '@{variables('ObservationID')}') and (Software eq '@{variables('SoftwareID')}') > success

 

Seems that if you do not include " ' " is considers the variable to be a column name. 

 

 

 

 

@Mira_Ghaly 

 

That problem is solved but, it leaves me with some other issues.

It seems to cause a infinite trigger loop, resulting in overwriting all the items that match the criteria.

See below flow I used.

 

Any idea why it is overwriting the title of all the items that match and not the only the one that is created/modified? 

 

Capture 9.JPGCapture 10.JPGCapture 11.JPGCapture 12.JPGCapture 13.JPGCapture 14.JPG

 

@mar01

Do you need your trigger to run on update or only create?

If you want it to run on update we need to add filter query on the settings of your trigger.

 

 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here

@Mira_Ghaly 

 

It needs to run on both update and create. 

 

 

 

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (1,965)