Hello,
I am trying to determine what the best methods are for relating new child records to parent records as they are created. Let me explain my setup. I have two tables one called parentDatabase with a one to many relationship with a table called childDatabase. The childDatabase table has a column that matches the unique value in the parentDatabase. I use that value in a lookup to relate the parent to the child record in a gallery.
(OnSelect property of a button in a gallery. Items are a filtered list of children records) -
LookUp(parentDatabase, uniqueValue = ThisItem.childUniqueValue)."name of the relationship",ThisItem)
This works correctly but I want to see if I can relate new child records as they are created in a ForAll patch. I think my issue with the forall patch might be the scope in my relate formula. I use "ThisRecord" to refer to the record within the forall patch but PowerApps seems to think that ThisRecord within the LookUp in the relate function are columns from the parentDatabase rather than the current value in the forall patch. The only error I get is that the relate function has invalid arguments.
Below I am trying to create the child record from values in a collection, then lookup the parent record to relate with the newly created child record.
ForAll(collection,
Patch([@childDatabase],Defaults([@childDatabase]),
{
childDatabaseRow: Column in collection,
childDatabase value to link back to parent: value in parentDatabase
}
);
Relate(LookUp(parentDatabase, uniqueValue in Parent = ThisRecord."value in parentDatabase").call_relationship,ThisRecord.id)
);
Is this approach correct? How can I get the scope of my formulas refer to the correct record?
I have spent a lot of time reading about the relate formula in the forums and microsoft's docs. I know that you can't put a use the relate function in a patch but I did not see any information saying you can't use it in a forall. Here is a forum post that tries to address a similar problem but ends up not using the relate function. Patch Lookup column dataverse - Power Platform Community (microsoft.com)
I appreciate any help or suggestions you can give.