I need some help solving this and thank you all in advance.
I have a collection that is bulit from user actions which has several columns:
the first three are created each time a Collect() is done. The FilePath gets created by running a Power Automate that is the returned value. The problem I am trying to solve is how, inside a ForAll(), I can use each File name value to pass as a parameter to the Power Apps run. command.
Here's what I am trying to do:
ForAll(Sequence(CountRows(colItems)),
Patch(colItems, Index(colItems, ThisRecord.Value),
{FilePath: SignaturePhoto.Run(<colItems.FileName>).FilePath })
);
I tried using ThisRecord.FileName but it doesn't work. So how do I specify the column value from the record in coItems being processed> This proably will be so obvious once someone responds.
Here's what did work.
When I did Collect() to add an item to the collection, I also did a Collect() to a duplicate collection. When the collection is complete, I then do this:
ForAll(colDuplicate,
Patch(colItems, ThisRecord,
{FilePath: "https://<stuff>" & <flowname>>.Run(varAction, ThisRecord.FileName,ThisRecord.,columnname>).varpath}
)
);
The flow returns the file path when it saves the item into a SharePoint library. colDuplicate is an exact copy of colItems so I use the ForAll on it but Patch the correspondind record in colItems.
I appreciate the helpful suggestions which got me to the right place.
I forgot that I switched to Seququence() because you can't patch a record in the collection used by ForAll().
Back to the drawing board.
Going with the simplier solution but thank you.
That appears to be workable as the expression works. Thanks
@lmheimendinger
One more thing, for your scenario to work correctly, Power Apps should await for the Flow to complete.
To make sure this happens, you must have at least one "Respond to a Power App or Flow" block in the Flow.
You also have to have one for there to be a return value to be used by FilePath in your Canvas App, and actually, also make sure to return an appropriate FilePath from the Flow for it to work correctly for your scenario.
@lmheimendinger
I don't recommend it (I recommend use my Patch outside ForAll way with the Collections instead), but if you really want to keep your original formula Patch inside ForAll, you may need to disambiguate ThisRecord like the following:
With({wColItems: colItems},
ForAll(wColItems,
Patch(colItems, wColItems[@ThisRecord],
{FilePath: SignaturePhoto.Run(ThisRecord.FileName).FilePath})
)
);
@lmheimendinger
Furthermore we should use Patch outside ForAll for better performing and easier to maintain formula, here's how:
To reduce the overhead of patching inside a ForAll
loop and instead collect the changes and patch them all at once, this can be achieved as follows:
First, you should create two collections, one for the base records and another for the changes. You can use the ForAll
function along with ClearCollect
for this purpose.
For the base records:
ClearCollect(colBaseRecs, colItems);
For the changes:
ClearCollect(colChangeRecs,
ForAll(colItems,
{
ID: ThisRecord.ID,
FilePath: SignaturePhoto.Run(ThisRecord.FileName).FilePath
})
);
Next, you can use the three-argument version of Patch
to apply the changes. This version takes the data source (in this case, your original collection), base records, and changes as arguments:
Patch(colItems, colBaseRecs, colChangeRecs);
See if this helps as well @lmheimendinger
Not sure why you use ForAll on Sequence?
Try like this:
ForAll(colItems,
Patch(colItems, ThisRecord,
{FilePath: SignaturePhoto.Run(ThisRecord.FileName).FilePath})
);
WarrenBelz
89
Most Valuable Professional
MS.Ragavendar
60
stampcoin
48