Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Create a counter limit on Gallery

(0) ShareShare
ReportReport
Posted on by 125

Help please! I am working on a form where I need to restrict the user's input to 5 items only. The user is using a text input box that is connected to a gallery and displaying the results they type in. After that I have a submit button to submit the entire form to a SharePoint list. I can't figure out how to code this to make it work properly. The following code is what I have for the "Add" button that adds the input to the gallery:

2023-01-26_16-37-37.png

Set(mycounter, 0);
If(IsBlank(TextInputStaticIP.Text),false, Collect(colStaticIPAddress, {IP: TextInputStaticIP.Text}));

(mycounter + 1)
If(mycounter > 5, Reset(Gallery7_1); Reset(TextInputStaticIP))

  • SteveAtTCH Profile Picture
    54 on at
    Re: Create a counter limit on Gallery

    hi @dixonbridgeta ... apologies, I misunderstood what you were trying to do...

     

    i think you should be able to accomplish what you're wanting to do by using concat to convert the collection of IP values into a single string, that you can then add to your sharePoint list...

    Concat and Concatenate functions in Power Apps - Power Platform | Microsoft Learn

     

    let me know if that makes sense or if you need any other input

  • dixonbridgeta Profile Picture
    125 on at
    Re: Create a counter limit on Gallery

    I did have something similar to that: 

    Patch(
    SPStorageRequest,
    ForAll(Gallery3.AllItems,
    {IPTests:colStaticIPAddress}));

     

    but the problem is that it is storing each gallery entry as a new item in list. So if there's 5 gallery items, I now have 5 rows of list items. What I want is for that gallery items to all store as one entry in the same column.

  • SteveAtTCH Profile Picture
    54 on at
    Re: Create a counter limit on Gallery

    you are quite welcome 🙂

    i think you just want to loop through all the elements in your collection and patch them to your list... so perhaps something like this:

    ForAll(colStaticIPAddress, 
     Patch(SharePointListName, Defaults(SharePointListName), 
     {
     SharePointColumnName: colStaticIPAddress[@IP]
     }
     )
    );




  • dixonbridgeta Profile Picture
    125 on at
    Re: Create a counter limit on Gallery

    Thank you so much @SteveAtTCH !! That worked! But now I am confused with how to get the data correctly over to my SP list as one item.

  • Verified answer
    SteveAtTCH Profile Picture
    54 on at
    Re: Create a counter limit on Gallery

    correct, somewhere other than the button's OnSelect property...

     

    so if that's been addressed, let's look at the logic where you're setting the counter...

     

    try something like this and see if it works for you:

    If(
     !IsBlank(TextInputStaticIP.Text) And mycounter < 5,
     Collect(colStaticIPAddress, {IP: TextInputStaticIP.Text});
     Set(mycounter, mycounter + 1),
     Notify("Sorry, you can only add 5 items at a time!", NotificationType.Information, 2000);
     Reset(Gallery7_1);
     Reset(TextInputStaticIP)
    );
  • dixonbridgeta Profile Picture
    125 on at
    Re: Create a counter limit on Gallery

    Hi @SteveAtTCH ! Thanks for responding.

    I had it in the button property. However, I just moved it to the "OnVisible" property of the screen and it still didn't work. Is that what you meant?

  • SteveAtTCH Profile Picture
    54 on at
    Re: Create a counter limit on Gallery

    hi @dixonbridgeta ... just to confirm you are setting mycounter on page visible, or OnStart of the application, not in the OnSelect property of the button, correct?

     

    if you are setting it on the button's OnSelect, your counter will never go beyond a value of 1 as each subsequent selection resets the counter back to 0

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,702 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,026 Most Valuable Professional

Leaderboard