Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

How to make Max+1 for the Record Number While running Patch command

(0) ShareShare
ReportReport
Posted on by

I have written the below code while running the patch command, so that it can obtain max+1 for each records

RecoNo:(First(Sort(colAllWsOrders, RecoNo, SortOrder.Descending)).RecoNo)+1
 
But the records which is posted having one time max+1, 
I mean the max+1, was 15+1 = 16, so all the records which been posted have the 16 as the value of the RecoNo,
While it should be 16, for next 17, and so on.
 
Please advise, what changes I should do to the code to achieve this.

 

 

 

Full code:

ForAll(
GalleryCartOrder.AllItems,
Patch(
WsOrderTables, Defaults(WsOrderTables),
{
RecoNo:(First(Sort(colAllWsOrders, RecoNo, SortOrder.Descending)).RecoNo)+1,
RefJobNo:Upper(TextBox2_21.Value),
IssueForModel:Upper(TextBox2_26.Value),
IssueForSerial:Upper(TextBox2_27.Value),
LineExtPrice:ThisRecord.CostPrice*Value(CartQty.Value)
}
)
);

 

  • Verified answer
    QuentinDURIEZ Profile Picture
    505 Super User 2025 Season 1 on at
    Re: How to make Max+1 for the Record Number While running Patch command

    Hi, 

     

     

    (First(Sort(colAllWsOrders, RecoNo, SortOrder.Descending)).RecoNo)+1

     

    This part of your formula is static since the number of items in colAllWsOrders 

     

    So to implement this correctly, you need to store the patched item into the said collection to have a +1 in each iterration

     

    ForAll(
    	GalleryCartOrder.AllItems,
    	
    	Collect(colAllWsOrders,
    		Patch(
    		WsOrderTables, Defaults(WsOrderTables),
    			{
    				RecoNo:(First(Sort(colAllWsOrders, RecoNo, SortOrder.Descending)).RecoNo)+1,
    				RefJobNo:Upper(TextBox2_21.Value),
    				IssueForModel:Upper(TextBox2_26.Value),
    				IssueForSerial:Upper(TextBox2_27.Value),
    				LineExtPrice:ThisRecord.CostPrice*Value(CartQty.Value)
    			}
    		)
    	)
    );

     

    I guess something like this should works. 

    Regards,

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

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,660 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard