0

I am reading this article https://learn.microsoft.com/en-us/training/modules/author-advanced-formulas-powerapps/4-forall-funct...

and it mentioned that ForAll is not guarantee to run in sequential order. for example if we have this formula, to loop through all groups >> all groups planners >> all planners tasks, as follow:-

ClearCollect(finalResult,{PlanTitle:"",TaskTitle:"",Status:"",AssignedToUserId:"",DueDate:"",TaskID:"",PlannerID:"",GroupID:""});
Clear(colRelatedGroupsIds);
Clear(colRelatedPlanners);
Clear(colRelatedPlannerTasks);

ClearCollect(colTeamSitesItem,Filter('Team Sites',1=1));
ClearCollect(colAllGroups,Office365Groups.ListGroups().value);
ForAll(colAllGroups As group,
ForAll(colTeamSitesItem As i2,

If(Lower(group.displayName)=Lower(i2.'Team Site Name'),
Collect(colRelatedGroupsIds,group.id))));

ForAll(colRelatedGroupsIds As group,
Collect(colRelatedPlanners,
Planner.ListGroupPlans(group.Value).value);

ForAll(colRelatedPlanners As planner,
Collect(colRelatedPlannerTasks,
Planner.ListTasksV3(planner.id,group.Value).value);
ForAll(colRelatedPlannerTasks As task,
ForAll(task._assignments As taskAssignment,
Patch(finalResult,Defaults(finalResult),
{
PlanTitle:planner.title,
AssignedToUserId:taskAssignment.userId,
Status:If(Text(task.percentComplete)="100","Completed",
   If(Text(task.percentComplete)="50","In Progress",
  If(Text(task.percentComplete)="0","Not Started"))),
TaskTitle:task.title,
DueDate:Text(DateTimeValue(task.dueDateTime), "dd/mm/yyyy"),
TaskID:task.id,
GroupID:group.Value,
PlannerID:planner.id
})


));RemoveIf(colRelatedPlannerTasks,true));RemoveIf(colRelatedPlanners,true));

and for it to work well, i need to run the formulas inside the ForAll in a sequential order to build the collection and remove its items, after each iteration, i do not want to have a case where the collection hold values from more than one iteration at a certain point in time, is this possible and how?

thanks

3
  • I've only glanced at your formula, so I definitely don't fully understand it, but is this something that could be done with a Power Automate flow that is executed from your canvas app? This would give you greater control over the parallelism and order it is processed.
    – user79408
    Commented Jun 23 at 0:53
  • @user79408 i tried to do this on power automate, and call this flow inside power apps, the issue is that the process will take more than 2 minutes so the flow is going to fail,, so i have to do it inside power apps Commented Jun 24 at 15:41
  • Is it important to get the output from your formula as soon as it's completed? If not, I'd still try using Power Automate with a "Respond to Power Apps" action somewhere at the beginning of your flow. I am doing something similar with an app that has a Move file flow. It can take hours for the flow to run but from the Power Apps users' perspective, they press the button, get a message informing that the process is underway and then the flow runs in the background. May not be suitable for your use case, but I just wanted to highlight that there may be other ways to achieve the same goal.
    – user79408
    Commented Jun 24 at 21:18

1 Answer 1

0

As far as I know (and what I have always done) is to set [Concurrency] On, and [Degrees of Parallelism] to 1, under the [ForAll] actions settings:

enter image description here

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.