web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : BAHUdP0KwZYjcNODXa9DIi
Power Apps - Building Power Apps
Answered

Patching an existing record in a Dataverse table from within a Forall

Like (0) ShareShare
ReportReport
Posted on 15 Apr 2022 19:42:31 by 41

I have a collection from a Dataverse table; 'Tickets'

 

ClearCollect(col_TicketsToBeRedeemed,
FirstN( Sort( Filter( Tickets, Redeemed_Date = Blank() And Ticket_Owner = "John@Smith.com"),
Issued_Date, Ascending), 1 ));

 

 With this collection 'col_TicketsToBeRedeemed', I need to loop through each individual record and update a field called 'Redeemed_Date' in the DB table.

 

ForAll( col_TicketsToBeRedeemed, 
 Patch( Tickets,
 LookUp( Tickets, ThisRecord.Id = col_TicketsToBeRedeemed[@Id]),
 { Redeemed_Date: Now() }
 )
);

 

The initial collection 'col_TicketsToBeRedeemed' was created from the same table I am attempting to Patch to. 'Tickets'

The column headers in the collection and table are the same.

The field 'Id' is a Autonumbered field type.

There is a Unique Identifier field 'ticketsid' which I've also attempted to match on but no luck.

I have tried many many different iterations of this in hopes of getting to work without success.

 

Any assistance would be much appreciated.

 

 

 

I have the same question (0)
  • Verified answer
    MF-11091236-0 Profile Picture
    41 on 16 Apr 2022 at 12:48:53
    Re: Patching an existing record in a Dataverse table from within a Forall

    @MichelK  I figured out it.  The column names causing the grief and by correcting I was able to successfully get to work.

    ClearCollect(col_TicketsToBeRedeemed, 
     FirstN( Sort(
     Filter( Tickets, Redeemed_Date = Blank() And Ticket_Owner = varCustomer.Email ), 
     Issued_Date, Ascending), varCustomer.QuantityToRedeem )
    );
    ForAll(col_TicketsToBeRedeemed As Row,
     Patch( Tickets, LookUp( Tickets, Id = Row.Id),
     { Redeemed_Date: Now() } );
    )

     

  • MichelK Profile Picture
    120 on 16 Apr 2022 at 10:06:05
    Re: Patching an existing record in a Dataverse table from within a Forall

    Deal
    Then can you try the following?

     

    ClearCollect(col_TicketsToBeRedeemed,
    FirstN( Sort( Filter( Tickets, Redeemed_Date = Blank() And Ticket_Owner = "John@Smith.com"),
    Issued_Date, Ascending), 1 ));
    UpdateIf( col_TicketsToBeRedeemed, true, { Redeemed_Date: Now() } );
    Patch( Tickets, col_TicketsToBeRedeemed ); //Could be Collect instead of Patch, forgot which one does the job

     

  • MF-11091236-0 Profile Picture
    41 on 16 Apr 2022 at 02:55:54
    Re: Patching an existing record in a Dataverse table from within a Forall

    I appreciate the response, the FirstN is intentional.  There could be multiple rows matching but only need to tag 'x'  number as being used.  In the filter provided some of the data is hardcoded where otherwise it would be dynamic.

    The goal of the filter is to retrieve 'x' number of the oldest rows for an individual.

    I have attempted the UpdateIf but unable to get 'x' number of rows which is important.

  • MichelK Profile Picture
    120 on 16 Apr 2022 at 00:29:03
    Re: Patching an existing record in a Dataverse table from within a Forall

    Hello @Slevin3900 ,

    First of all, in the following expression :

    ClearCollect(col_TicketsToBeRedeemed,
    FirstN( Sort( Filter( Tickets, Redeemed_Date = Blank() And Ticket_Owner = "John@Smith.com"),
    Issued_Date, Ascending), 1 ));

    The FirstN( Collection, 1 ) returns only one record. So if the objective is to update just the first one, there would not be a need for a ForAll, and you would just use the following code:

    Patch(Tickets,First( Sort( Filter( Tickets, IsBlank(Redeemed_Date) And Ticket_Owner = "John@Smith.com"),
    Issued_Date, Ascending))), {Redeemed_Date : Now()});

    However, if you need to update all the matching records and the FirstN was unintentional, you could use an UpdateIf :

    UpdateIf( Tickets,  IsBlank(Redeemed_Date) And Ticket_Owner = "John@Smith.com", {Redeemed_Date: Now()});

     

    Let me know if this helps! 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete