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
Super User

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
Super User

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,510)