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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patching collection us...
Power Apps
Unanswered

Patching collection using ForAll with LookUp Collumn

(1) ShareShare
ReportReport
Posted on by 6
Hello, I've lost so many hours trying to figure this one out!
 
I'm trying to patch a collection called "colDrawingImport" to two Dataverse tables. The first table patches okay. The second table has a lookup to the first which is where I'm having the issue. 
 
My first table is called "ProjectDocuments", and I patch all my collection as follows, which works just fine:
 
Patch(
    ProjectDocuments,
    ForAll(colDrawingImport,
    {Type:ProjectDocumentType.'Client Documents',
    DocumentNumber:ThisRecord.Number,
    Project:Bulk_NewDocProjectInput.Selected,
    AppStatus:ThisRecord.AppStatus,
    Category:ThisRecord.Category,
    Priority:Value(ThisRecord.Priority),
    ProductionStatus:ProductionStatus.'Not Started'}
));
 
My second table is a revision history table where there is a lookup column called "Document", this "Document" column looks up from the "ProjectDocuments" table.
When I patch this table on a single item else where in the app (not from my collection), I use the following code which works perfect:
 
Patch(
    ProjectDocRevHistories,
    Defaults(ProjectDocRevHistories),
    {RevisionHistoryID:NewDocNumberInput.Value&"-"&Right(Concatenate("0" & NewDocRevInput.Value),2),
    Document:LookUp(ProjectDocuments,NewDocNumberInput.Value=DocumentNumber),
    Revision:NewDocRevInput.Value,
    AppStatus:NewDocRevStatusInput.Selected.Value,
    DateReceived:NewDocRevReceivedInput.SelectedDate}
);
 
 
However, when I try to patch this table for a whole collection and therefore within a "ForAll", I can't work out how to lookup the record to patch the "Document" column.
I have tried so many things, but at the moment I have the following, which is not working:
 
Patch(
    ProjectDocRevHistories,
    ForAll(colDrawingImport,
    {Document:LookUp(ProjectDocuments,ThisRecord.DocNumber=ProjectDocuments.DocumentNumber),
    RevisionHistoryID:ThisRecord.Number&"-"&Right(Concatenate("0" & ThisRecord.Revision),2),
    Revision:ThisRecord.Revision,
    AppStatus:ThisRecord.RevStatus,
    DateReceived:ThisRecord.DateRecived})
)
 
My "colDrawingImport" Collection looks like this:
 
 
Where the DocNumber column has been created with the following AddColumns formula:
 
DocNumber,
    LookUp(ProjectDocuments,DocumentNumber=Value)
 
Is there a way to make the "DocNumber" column in the collection a record instead of a table, which would then make the ForAll patching easier?
Or is there a simple bit of code to use on the Patching of the "Document" column where I can still lookup the correct record to be patched?
 
 
Hopefully I've explained that fully enough for someone to know what I need!
Really appreciate help on this one, I've lost nearly a full day on this one! 
 
 
 
 
Categories:
I have the same question (0)
  • BhargavPatel Profile Picture
    660 Moderator on at
      Can you trying the below Power Fx? I changed ThisRecord.DocNumber to ThisRecord.DocNumber.DocumentNumber
     
    Patch(
        ProjectDocRevHistories,
        ForAll(colDrawingImport,
        {Document:LookUp(ProjectDocuments,ThisRecord.DocNumber.DocumentNumber = ProjectDocuments.DocumentNumber),
        RevisionHistoryID:ThisRecord.Number&"-"&Right(Concatenate("0" & ThisRecord.Revision),2),
        Revision:ThisRecord.Revision,
        AppStatus:ThisRecord.RevStatus,
        DateReceived:ThisRecord.DateRecived})
    )
     
  • LT-11102220-0 Profile Picture
    6 on at
    Hi, thanks for the response, I actually managed to fix my question about 30 mins after posting here. 
     
    I did try your suggestion also, but it did not work. The solution was as follows:
     
    Patch(
        ProjectDocRevHistories,
        ForAll(colDrawingImport,
        {Document:LookUp(ProjectDocuments,DocumentNumber=colDrawingImport[@Number]),
        RevisionHistoryID:ThisRecord.Number&"-"&Right(Concatenate("0" & ThisRecord.Revision),2),
        Revision:Value(ThisRecord.Revision),
        AppStatus:ThisRecord.RevStatus,
        DateReceived:ThisRecord.DateRecived}));
     
    Cheers!
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,041

#2
11manish Profile Picture

11manish 676

#3
Valantis Profile Picture

Valantis 655

Last 30 days Overall leaderboard