cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bpremji
Regular Visitor

Patching CDS records in a ForAll Loop with Lookup Value

Hi all,

 

I have created a collection with 4 fields.  Two text fields and two 'Lookup fields', it looks like this in the View Collections:

 

1.PNG

 

I am trying to use these fields to create CDS records for a custom entity which has 2 lookup fields that correspond to the 2 lookup fields in the Collection.  If I run the following code:

 

ForAll(
 CollectionDeliveryStaff1,
Patch(
'Delivery Staff',
Defaults('Delivery Staff'),
{Name:RowNumber}
)
);

 

CollectionDeliveryStaff1 is the name of the collection

Delivery Staff is the name of the entity in CDS

the records get created:

 

2.PNG

 

However I cant seem to get the syntax correct to set a lookup field.  I have tried:

 

ForAll(
CollectionDeliveryStaff1,
Patch(
'Delivery Staff',
Defaults('Delivery Staff'),
{Name:RowNumber,Lecturer:aqs_StaffId}
)
);

 

where Lecturer is the name of the lookup field in the cds entity I am trying to populate and the aqs_StaffId is the field from the Collection.

 

The error message I am getting is:

3.PNG

 

It seems I cant reference the field as the Patch function is not a traditional For Each Loop.

 

Appreciate any help

 

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
rampprakash
Super User
Super User

Hello @bpremji 

 

You can try below code

 

ForAll(
CollectionDeliveryStaff1,
Patch(
'Delivery Staff',
Defaults('Delivery Staff'),
{Name:RowNumber,
Lecturer:LookUp(  
       staffidTableName,  
       staffuniqueName = GUID(aqs_StaffId)  
     )
}
)
);

 

if aqs_StaffId is string you need to use GUID(aqs_StaffId) else you can directly use aqs_StaffId

 

Please mark as Answer if it is helpful and provide Kudos


Subscribe : https://www.youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLA
Blog : https://microsoftcrmtechie.blogspot.com

 

 

View solution in original post

1 REPLY 1
rampprakash
Super User
Super User

Hello @bpremji 

 

You can try below code

 

ForAll(
CollectionDeliveryStaff1,
Patch(
'Delivery Staff',
Defaults('Delivery Staff'),
{Name:RowNumber,
Lecturer:LookUp(  
       staffidTableName,  
       staffuniqueName = GUID(aqs_StaffId)  
     )
}
)
);

 

if aqs_StaffId is string you need to use GUID(aqs_StaffId) else you can directly use aqs_StaffId

 

Please mark as Answer if it is helpful and provide Kudos


Subscribe : https://www.youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLA
Blog : https://microsoftcrmtechie.blogspot.com

 

 

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (4,193)