cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lexicron
Resolver II
Resolver II

How to use ForAll(collection) and Patch(cdsentity) if the collection contains records from the same cds entity? Meaning column names are identical

I've collected into my CollectionX a few records from CDSEntityY. Hence their column names are all identical.

 

The unique ID field for my CDSEntityY is CDSEntityYID.

 

I need to use that CollectionX as part of my ForAll+Patch function to update a field for those collected records, but I'm getting a problem in the LookUp line.

 

 

ClearCollect(
    CollectionX,
    Filter(
        CDSEntityY, 
        FieldA="some value"
    )
);

ForAll(
    CollectionX,
    Patch(
        CDSEntityY,
        LookUp(CDSEntityY, CDSEntityYID=CollectionX[@CDSEntityYID]),
        {
            FieldB:"some value"
        }
    );
);

 

 

LookUp(CDSEntityY, CDSEntityYID=CollectionX[@CDSEntityYID])

The above used to work (I can run it and it does what I want). However, now even though it's not underlining the code in red or blue, it's giving me a red error flag on runtime, and it doesn't work. The error says the right side of the 'Equal' operator must be a constant value. I don't know how to achieve that and still have it do what I want.

 

I've also tried LookUp(CDSEntityY, CDSEntityYID=CDSEntityYID)

but that doesn't work either. Same error on runtime (but no red or blue underline).

 

Can someone help please? Could it be one of my app settings as well?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User III
Super User III

Hi @Lexicron ,

Try

ClearCollect(
    CollectionX,
    RenameColumns(
       Filter(
          CDSEntityY, 
          FieldA="some value"
       ),
      "CDSEntityYID",
      "CDSID"
   )
);

ForAll(
    CollectionX,
    Patch(
        CDSEntityY,
        LookUp(CDSEntityY, CDSEntityYID=CDSID,
        {
            FieldB:"some value"
        }
    )
);

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

2 REPLIES 2
WarrenBelz
Super User III
Super User III

Hi @Lexicron ,

Try

ClearCollect(
    CollectionX,
    RenameColumns(
       Filter(
          CDSEntityY, 
          FieldA="some value"
       ),
      "CDSEntityYID",
      "CDSID"
   )
);

ForAll(
    CollectionX,
    Patch(
        CDSEntityY,
        LookUp(CDSEntityY, CDSEntityYID=CDSID,
        {
            FieldB:"some value"
        }
    )
);

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

Perfect!! Thank you so much! 😄

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (3,004)