I'm needing some advice for a Get records function. If anyone can advise on the below it would be appreciated. We are trying to add a condition that will list all the records for a particular value, and process the first record that is found. So far this part of the flow is functioning like this:
'Apply to Each' connector refers to a previous connector that 'Gets all Invoice Products',
A condition is in place to check that a 'Schedule' field value is set to 'Run',
____ > > > and here I would like to get the first record that has this value.
Can anyone advise how to get the first record?
Solved! Go to Solution.
You can use the List records action and then get the first record of all the filtered records using this expression -
You can also use this blog post as a reference, apologies but your image is of bad quality and so I am unable to view the stuff in it but I think the above expression will definitely solve your issue out.
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
Hi @yashkamdar ,
Thanks for your reply and the expression you provided.
I've been trying to work with it, but struggling with where to insert the field and the value to be filtered by.
Using the expression provided - first(body('List_records')?['value'])?['particularValue'] - I've tried the following two expressions but am coming back with the error message listed below.
Unable to process template language expressions in action 'Get_the_first_Invoice_Product_set_to_Schedule_Next_Flow' inputs at line '1' and column '3021': 'The template language expression 'first(body('Get_all_Invoice_Products')?['value']?['948180002'])' cannot be evaluated because property '948180002' cannot be selected. Array elements can only be selected using an integer index. Please see https://aka.ms/logicexpressions for usage details.'.
Any feedback or advice on this is greatly appreciated - I"m just sure how to update expression
An update for anyone that can assist with this.
I wasn't able to get the first record expression to function correctly, so I'm also trying to do a filter query in the List Records while putting the Top Count to 1, so it will only bring back 1 record.
When running the flow I'm getting an error that says:
I understand the error - but I'm trying to filter the list of records down to 1 record that currently has the value of 941880002 in the option set.
I'm still working on this so I might keep posting here in case anyone can help.
I moved to using a List all Records connector that has the following details in it:
filter query: FieldSchemaName eq 948180002 (option set value)
Order By: createdon
Top Count: 1
I had thought the Top Count row would mean that it would only pull back 1 row, but not happening.
My next step is to update a record, but as I'm pulling 3 to 4 records in the list all records they are all updating, instead of the first one that has the FieldSchemaName of 948180002.
Should I be adding the first expression into the update a record connector, or into a step before that?
Hi @Mira_Ghaly ,
I'm not sure how much you are wanting of the flow run, but these are the connectors involved from the a 'successful' run. I hope it's not too blurry.
@Mira_Ghaly - I should add that I do expect that with the initial successful one that it will list 3 to 4 records. But I just want the first record. With this record I update a field to trigger another flow. The step before the List Records is to update the current Invoice Product so it no longer meets the criteria to be picked up in the List All Records.
Hi @Mira_Ghaly ,
Thanks for your replies on this query it has helped me resolve the problem.
You were right that the apply to each was causing the loop, so it wasn't just updating the one record. I did try pulling it out of the loop yesterday but since realised that I was referencing a List All Items in the connector. I removed this and was able to run the flow as requested.
For anyone else trying to access one record from the List All Records, this is what resolved it for me:
First - we had 4 invoice products going onto the invoice. They were being added at the same time, so we had one product with an option set value of 'update required', and the others were 'schedule update'.
Second - The List all records (below - List Invoice Products that eq Schedule) picked up records that had 'schedule update', and took the first record found. This record was updated to 'update required' and it cycled through the next run.
Third - This continued until all 4 records were processed for the update. This seems like a complete run around - but it is achieving the required result. Good luck to anyone else!
But I prefer the second solution: using this formula in my variables from Dataverse Get List Rows:
It works fine If you want to achieve the first item/row of the List!
Keep up to date with current events and community announcements in the Power Automate community.
A great place where you can stay up to date with community calls and interact with the speakers.
Check out the latest Community Blog from the community!