I am trying to figure out if it is possilbe to do two things inside a ForAll loop or if I must do two loops. I need to do a an If to set a variable and then use that variable in a patch. I guess I could do a nested if or reproduce the patch statement lots of times. It would just be so much cleaner if I could do If then a Patch within the same loop.
Solved! Go to Solution.
Hi @BrianHFASPS
You should be able to run multiple functions in a ForAll loop by using the semi-colon character to separate each function. Maybe you could post the error that you're receiving?
Here's an example I just put together that works for me.
ClearCollect( InputCollection, {legs: 4,desc: "cat"}, {legs: 4,desc: "dog"}, {legs: 2,desc: "monkey"} ); ForAll( InputCollection, If(legs = 2,Collect(TwoLegCollection, {desc: desc})); If(legs = 4,Collect(FourLegCollection, {desc: desc})) )
Notice the 'trick' I'm using here. Although you can't use ClearCollect or Set inside a ForAll, you can use Collect. So instead of storing data values in variables, you can Collect them into a temporary collection and carry out whatever tasks you need to carry out after the ForAll loop.
Hi @BrianHFASPS
Although it's possible to do multiple things inside a ForAll loop, setting variables is something that isn't allowed. Theoretically, PowerApps can execute the contents of a ForAll loop in parallel, so this is the reason why calls to Set or ClearCollect are not permitted.
Very good to know. That is great thing for performance but would definitely break my methods. How can you do multiple things in ForAll() loop though? I can't figure out syntax?
ForAll(Collection,
If(),
If()
)
Doesn't work or ; it seems. What am I missing?
Hi @BrianHFASPS
You should be able to run multiple functions in a ForAll loop by using the semi-colon character to separate each function. Maybe you could post the error that you're receiving?
Here's an example I just put together that works for me.
ClearCollect( InputCollection, {legs: 4,desc: "cat"}, {legs: 4,desc: "dog"}, {legs: 2,desc: "monkey"} ); ForAll( InputCollection, If(legs = 2,Collect(TwoLegCollection, {desc: desc})); If(legs = 4,Collect(FourLegCollection, {desc: desc})) )
Notice the 'trick' I'm using here. Although you can't use ClearCollect or Set inside a ForAll, you can use Collect. So instead of storing data values in variables, you can Collect them into a temporary collection and carry out whatever tasks you need to carry out after the ForAll loop.
Hello,
The solution don't work with me :
I get the msg "Number of arguments not ok : 3 given, 2 asked" :
See my code below :
ForAll(
LISTE_ELEMENTS.Elements;
ForAll(
Elements;
Collect(
ExportCSVCol;
{
Titre4:Text(field_1);
Titre5:Text(Title);
Titre6:Text(field_2);
Titre7:Text(field_3);
Titre8:Text(field_4);
Titre9:Text(field_5);
Titre10:Text(field_6)
}
)
);;
Collect(
ExportCSVCol;
{
Titre1:LISTE_ELEMENTS.field_9;
Titre2:LISTE_ELEMENTS.field_10
}
)
)
Maybe that's no longer possible ?
Have you got any idea @timl ?
I think some of your ; (semi-colons) need to be , (commas)
LISTE_ELEMENTS.Elements;
Elements;
ExportCSVCol;
Hi,
In my version of power apps, the commas are not recognized
You're missing a ) to close out the inner ForAll()
i don't think so... but the the msg "Number of arguments not ok : 3 given, 2 asked" is strange if it's possible to put two functions in one ForAll()
User | Count |
---|---|
246 | |
103 | |
82 | |
49 | |
42 |