cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sigmaNot
Helper I
Helper I

Add empty records to a collection dynamically based on a variable

Context:

I am building a voting form (of sorts) for a recurring annual process at work.  The form needs to capture nominations, but the total allowed nominations per vote will vary from year to year.  I have setup a global variable to indicate what this "total nominations allowed" will be:

 

Problem:

In order to capture nominations I created a collection that feeds into a gallery control which the user can interact with in order to make their selections. 

How can I pre-emptively create the collection and add X empty records based on "total nominations allowed" number above?

 

I'm trying to avoid the solution below as I would need to adjust this piece of code every year depending on that "total nominations allowed" number:
ClearCollect(colNominations,
    {col1: Blank(), col2: Blank(), ... , coln: Blank()},

    {col1: Blank(), col2: Blank(), ... , coln: Blank()},

    ....

    {col1: Blank(), col2: Blank(), ... , coln: Blank()}

)

1 ACCEPTED SOLUTION

Accepted Solutions
rizkyaditya
Resolver III
Resolver III

Hello @sigmaNot ,

 

You can try this to create that collection :

ForAll(Sequence(yourtotalNominationsAllowed_Variable) As totalNominationsAllowed, Collect(colNominations, {Id: totalNominationsAllowed.Value, yourColumn1: Blank(), yourColumn2: Blank()}))

 

I hope this helps!

View solution in original post

2 REPLIES 2
rizkyaditya
Resolver III
Resolver III

Hello @sigmaNot ,

 

You can try this to create that collection :

ForAll(Sequence(yourtotalNominationsAllowed_Variable) As totalNominationsAllowed, Collect(colNominations, {Id: totalNominationsAllowed.Value, yourColumn1: Blank(), yourColumn2: Blank()}))

 

I hope this helps!

Exactly what I was looking for!

 

Was not aware of the Sequence function, but it seems like this is the closest to an index loop that PowerApps offers.

 

Thanks.

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 (3,481)