Skip to main content

Notifications

Community site session details

Community site session details

Session Id : pG/ZdyqXrelxarngE2TQp6
Power Automate - Building Flows
Answered

Retrieve Dataverse row count (& use it) without "for each"

Like (1) ShareShare
ReportReport
Posted on 11 Jun 2024 21:52:13 by

I have a flow which adds a new row to a dataverse table called "Projects."

I need to populate one of the new fields in the Projects table with the next available incremental number from the column "Master Project #"

I can retrieve the max number in the column "Master Project #" by using "List Rows" and sorting by the column in descending order & using a row count of 1.

My trouble is that I then need to insert this number into the "new row" step without turning it into a "for each" step.

Is there a better way to retrieve and use the highest number in the "Master Project #" column plus one?

  • Verified answer
    BertP Profile Picture
    on 12 Jun 2024 at 21:27:22
    Re: Retrieve Dataverse row count (& use it) without "for each"

    Thank you so much @abm 

     

    After searching around, I seem to have found the right syntax, which was as follows:

    @{outputs('List_Master_Project_Number')['body']['value'][0]['cra6a_masterproject']}

     

    Thanks so much for setting me on the right path!

  • abm abm Profile Picture
    32,464 Most Valuable Professional on 12 Jun 2024 at 08:49:41
    Re: Retrieve Dataverse row count (& use it) without "for each"

    Hi @BertP 

     

    Could you post a screenshot of your flow please? Since your using the List rows with row count 1 it will always put the loop even though it contains one record hence I suggested the expression. 

     

    Is here 'name' is your column, which is your incremental column?

     

    outputs('List_Master_Project_Number')?['body']?[0]?['name']' 

     

    You mentioned have a "for each" step because the flow ultimately will only be adding a single record/row (it depends on a single row JSON output from powerapps for adding a single row).

     

    Could you please explain the above?

     

    outputs('List_Master_Project_Number')?['body']?[0]?['here replace your incremental column']' 

     

     

    Thanks

  • BertP Profile Picture
    on 12 Jun 2024 at 00:11:41
    Re: Retrieve Dataverse row count (& use it) without "for each"

    thx @abm 

     

    I'm not sure I explained the difficulty well enough. I am trying to retrieve the max value (whole number) of the column "Master Project #" plus 1 in a way that I can use a single number output. My problem is that when I put in any references to the "List Rows" step, PA creates a "for each" step. I can't have a "for each" step because the flow ultimately will only be adding a single record/row (it depends on a single row JSON output from powerapps for adding a single row).

     

    I tried the code you had above, but receive the following error: " 'outputs('List_Master_Project_Number')?['body']?[0]?['name']' cannot be evaluated because property '0' cannot be selected. Object properties can only be selected by names."

  • abm abm Profile Picture
    32,464 Most Valuable Professional on 11 Jun 2024 at 22:58:20
    Re: Retrieve Dataverse row count (& use it) without "for each"

    Hi @BertP 

     

    Yes you can specify the index try the below

     

    image.png

     

    outputs('List_rows')?['body/value']?[0]?['name']

     

     

    Note: When you use "List Rows" and sorting by the column in descending order & using a row count of 1. This will return the latest record you created. So better to add another filter query to extend using the  incremental number column not equal to zero or something. This will give you the second last record not the very latest record. Not sure this is the logic you want but I just want to mention that and it may be helpful.

     

     

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,710 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,030 Most Valuable Professional

Leaderboard