cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
OJBridger
Frequent Visitor

Getting a counter to increment in a ForAll statement

Hello all,

 

I've run into an issue that I can't seem to get around.

 

ForAll(
Set(Counter, 1);
FirstN(
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],
CountRows(SelectedPersonel)),
Patch(<DATA_SOURCE>, Defaults(<DATA_SOURCE>),
{
BriefHeader: DataCardValue5.Text,
BriefOn: DatePicker1.SelectedDate,
Item1:DataCardValue18.Text,
User: Concat(FirstN(LastN(SelectedPersonel, Counter)), Name)
}
)
);
Set(Counter, Counter +1);

 

What this does is creates a new SharePoint list entry, with 1 changing field "User". I have it all working apart from getting the "Counter" to increment by 1, I need the Counter to go from 1>2>3>4 for each time a SharePoint List item is created (What this does is create a list item that is identical, apart from the user which will change).

 

When I manually put an integer instead of the Counter it all works perfectly, so typing in 1..then 2... Obviously I want this to be automated!


Where do I need to slot in Set(Counter, Counter +1); ? I've tried but it throws an error for using Set() in a ForAll

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
BCLS776
Super User
Super User

In Power Apps, a ForAll is more like a table operation than a looping function. Let the ForAll do the counting for you by feeding it the table of data you want to operate on. For example, if you have a table with a column of names try this:

ForAll(Personel,
    Patch(<DATA_SOURCE>,Defaults(<DATA_SOURCE>),
    {
        BriefHeader: DataCardValue5.Text,
        User: ThisRecord.Name
        // And so on
    }
    )
)

Does that fit with what you are trying to do?

 

Bryan

 

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

View solution in original post

2 REPLIES 2
BCLS776
Super User
Super User

In Power Apps, a ForAll is more like a table operation than a looping function. Let the ForAll do the counting for you by feeding it the table of data you want to operate on. For example, if you have a table with a column of names try this:

ForAll(Personel,
    Patch(<DATA_SOURCE>,Defaults(<DATA_SOURCE>),
    {
        BriefHeader: DataCardValue5.Text,
        User: ThisRecord.Name
        // And so on
    }
    )
)

Does that fit with what you are trying to do?

 

Bryan

 

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

This is perfect! Thank you. Thinking about it this way and using the ForAll to do the counting is a perfect solution that is also much simpler 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,191)