Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

Increment gallery records

Posted on by 37
The code below works fine and increments rows from a collection connected to a gallery. I want to have it increment up until a title row and then reset to 1 on the first row after the title. The title data will be blank on the rows it needs to increment: 
 
Please modify:
 
ClearCollect(
    editTable,
    ForAll(
        Sequence(CountRows(editTable)),
        Patch(
            Last(FirstN(editTable, Value)),
            {RowNumber: Value}
        )
    )
);  
  • ronaldwalcott Profile Picture
    ronaldwalcott 1,058 on at
    Increment gallery records
    Didn't realise that.
     
    Instead of using a variable we can try using a table with patch.
     
    Set(incrementTable, Table({valueIncrement:1}));
     
    Patch(incrementTable, First(incrementTable), { valueIncrement:First(incrementTable).valueIncrement + 1 })
     
    Replace as appropriate and see if it works. I am assuming that Patch does not execute concurrently and ForAll waits for the completion.
  • geraldc1820 Profile Picture
    geraldc1820 37 on at
    Increment gallery records
    Thank you. That concept makes sense but PowerApps will not allow variables set inside a ForALL.
  • Suggested answer
    ronaldwalcott Profile Picture
    ronaldwalcott 1,058 on at
    Increment gallery records
    Create a new variable incrementValue set it to 1 before the ClearCollect
    You are still incrementing using Value but setting the increment to the record based on the new incrementValue variable
    You reset the incrementValue based on your condition back to 1. Not sure what you meant by after so you may have to move where you do the reset and reset to 0 instead then increment.
    The syntax is a bit off I am not typing on my desktop and I don't know exactly the condition you are checking for.
     
    Something like this should work
     
     
    UpdateContext({incrementValue: 1});
     
    ClearCollect(
        editTable,
        ForAll(
            Sequence(CountRows(editTable)),
            If(titlerowvaluecheck,UpdateContext({incrementValue: 1}));
            Patch(
                Last(FirstN(editTable, Value)),
                {RowNumber: incrementValue}
            );
            UpdateContext({incrementValue: incrementValue + 1});
        )
    );  

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,532

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,050

Leaderboard