cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tarjani
Advocate III
Advocate III

Get first record on a list

Hi all,


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?

 

Tarjani_0-1598860161050.png

 





1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Tarjani,

The List Invoice Products that eq schedule returned only 1 record, but executed for times as it is placed inside the apply_to_each

 

Mira_Ghaly_0-1599006286981.png

 

 

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

View solution in original post

10 REPLIES 10
yashkamdar
Solution Sage
Solution Sage

Hello Team,

 

You can use the List records action and then get the first record of all the filtered records using this expression - 

 

first(body('List_records')?['value'])?['particularValue']

 

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.

 

Reference article - https://www.tachytelic.net/2020/01/power-automate-stop-apply-to-each-list-records/

 

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.

1.   first(body('Get_all_Invoice_Products')?['948180002']?['ec_scheduleflowupdate'])


2.   first(body('Get_all_Invoice_Products')?['ec_scheduleflowupdate']?['948180002'])


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:

A binary operator with incompatible types was detected. Found operand types 'Edm.Int32' and 'Edm.String' for operator kind 'Equal'.

 

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? 

 

 

 

Tarjani_0-1599004602466.png

 

@Tarjani 

Top Count = 1 Should return only 1 record can you provide screenshot from your Flow History please?

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

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.

Tarjani_0-1599005808207.png

Tarjani_1-1599005817027.png

 

 

@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.

Tarjani_0-1599006062229.png

 

 

Hi @Tarjani,

The List Invoice Products that eq schedule returned only 1 record, but executed for times as it is placed inside the apply_to_each

 

Mira_Ghaly_0-1599006286981.png

 

 

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

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!

 

list all records.jpg

David_Pezzoli
Kudo Collector
Kudo Collector

But I prefer the second solution: using this formula in my variables from Dataverse Get List Rows:

first(outputs('Step_Name_Get_List_Rows')?['body/value'])?['attribute_name']

 

 

It works fine If you want to achieve the first item/row of the List!

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!

Users online (6,363)