I was hoping someone could help or shed some light on a situation with nested Patch functions.
I have a function carrying out a ForAll function, within which, I basically need to create a "parent" list item for a Sharepoint List Item.
As I cannot create variables inside a ForAll function, I was hoping to leverage the fact that the Patch function (for the "parent" record) returns the created record - I could then use that returned value to set the foreign key of the original item being patched:
ForAll(UpdateCollection, // A List of ChildList Record ID's that need to be updated
Patch(ChildList,LookUp(ChildList,ID=UpdateCollection[@ID]),
{
Parent_ID: Patch(ParentList,Defaults(ParentList), { Title: "New ParentList Record" } ).ID
}
)
);
The "Inner" patch is working fine - I can confirm that the "parent" record is being created correctly, but the "outer" patch is NOT updaing the "Parent_ID" of the ChildList record.
Is there some sort of limitation for nesting Patch functions?
Is it to do with the order in which the patches take place? Perhaps the runtime compiler cannot interrupt a patch function with another patch function and then carry on with the 1st patch function.
Or, if all else fails, can anyone else think of another way to achieve the same result? (keeping in mind that you cannot use Set or UpdateContext within a ForAll function) - The only other method I can think of means looping through the entire UpdateCollection 3 times (1. to create parent records, 2. to patch UpdateCollection with lookup to parent record list, 3. to patch child record list)
Many thanks to anyone that can help.
James.
P.S. I find it amusing that on the the "PowerApps Community Forum", the code snippet function does not have a language style for "PowerApps Script"! - I mean, I love PowerApps, but you gotta love Microsoft for it's lack of common sense sometimes...