web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Create a counter limit...
Power Apps
Unanswered

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))

Categories:
I have the same question (0)
  • SteveAtTCH Profile Picture
    54 on at

    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

  • dixonbridgeta Profile Picture
    125 on at

    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?

  • Verified answer
    SteveAtTCH Profile Picture
    54 on at

    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

    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.

  • SteveAtTCH Profile Picture
    54 on at

    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

    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

    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

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard