cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tamras
Level 10

First and Subsequent Rows (ForAll)

I currently have the following formula on Form1 OnSuccess

ForAll(ReviewerCollection, If(!IsBlank(LineEmail) && !IsBlank(LineAction), Patch(Task, Defaults(Task), {MasterID:Form1.LastSubmit.ID, Title:Form1.LastSubmit.Title, TrackNum:Form1.LastSubmit.RFNum, ReviewerText: LineEmail, ActionRequired: LineAction})))

How do I assign the first record with different value that subsequent records? I want to populate additional fields in Task list for example,

  • First record:  RoutingOrder: 1, Status: "In Progress"
  • Subsequent records: Routing Order: RoutingOrder +1, Status: "On Hold"

The routing order should be sequential based on how the gallery items are ordered (top to bottom). 

Task list will be used to store all tasks unrelated to current item.  The MasterID will be used to filter associated tasks. 
RoutingOrder is a text field (but should probably be converted to number field). The number should always start at 1 for each group of related tasks. I'm thinking I  need it to start at 1 for Flow to identify the order for which to send an email (i.e. when reviewer1 completes tasks an email should be sent to reviewer2).  I'm trying to create a round-robin scenario but each reviewer is also free to branch off and send the item for review to another set of reviewers.  At least these are my requirements for this app.

Status is a text field. 
Datasource is SharePoint Online.

3 REPLIES 3
Community Support Team
Community Support Team

Re: First and Subsequent Rows (ForAll)

Hi @Tamras ,

Could you tell me

1)what's your data source?

2)what's RoutingOrder and Status's data type?

I assme that you use SharePoint list as data soure ,RoutingOrder is number type and Status is text type.

Firstly, it's not supported to set variable inside the ForAll function.

So if you want to update RoutingOrder with incremental number, I suggest you use the ID field.

Secondly, about the status, I suggest you update all the status to "On Hold" and then update the first record to "On Progress".

ForAll(test,Patch(listname,LookUp(listname,ID=test[@ID]),
{RoutingOrder:LookUp(listname,ID=test[@ID],ID),Status:"On Hold"}));
Patch(listname,First(listname),{Status:"In Progress"})

Best regards,

Community Support Team _ Phoebe Liu

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Super User
Super User

Re: First and Subsequent Rows (ForAll)

Patch(Task, Defaults(Task), {RoutingOrder: CountRows(Task)+1, Status: If(CountRows(Tasks)>0,"OnHold","InProgress")})

Assuming you clear out your collect each time, you could use the above in your ForAll loop.

You can't use Set or UpdateContext in a ForAll loop (though there is a trick to get around that) but you can check how many rows you've added to your collection. On the first iteration CountRows(Tasks) will return zero, on the second iteration it will be 1 and so on.

Hope that helps...

Tamras
Level 10

Re: First and Subsequent Rows (ForAll)

@PaulD1 I probably should have mentioned "Task" is a repository for all -- so there would be existing items in there already before patching the current app. I maybe need to filter the Task list based on MasterID first? If there are existing items CountRows(Task)>0 will always be true.

ForAll(ReviewerCollection, If(!IsBlank(LineEmail) && !IsBlank(LineAction), Patch(Task, Defaults(Task), {MasterID:Form1.LastSubmit.ID, Title:Form1.LastSubmit.Title, TrackNum:Form1.LastSubmit.RFNum, ReviewerText: LineEmail, ActionRequired: LineAction, RoutingOrder: CountRows(Task)+1, Status: If(CountRows(Task)>0, "On Hold", "In Progress")})))

  @v-yutliu-msft I edited my first post. I'll try your suggestion and report back. Thanks. 

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (6,255)