Limit volume of database rows

Options
Hey all, does anyone know if there’s a way to set a rule of maximum number of database rows?

I’m creating a voucher code system and want to stipulate that no more than 50 rows (vouchers) can be redeemed, each with unique identifiers.

Thanks in advance 😊

Comments

  • Kevin Wasie
    Kevin Wasie Member
    Options
    You want to limit the number of rows on the whole table? Or, you want to limit the number of records for a particular criteria .. such as "Only allow 50 records for #voucher_company#"

    I'm guessing it's the later option ... you can do this with logic inside of your endpoint or function. 

    When the request to add a new comes in, use a Query All function, with a where clause. Only select the vouchers with the same identifier. On the output, use Count.

    Now, your function will return the number of vouchers that currently exist.

    Then, use a Precondition (under utility functions).Set the expression to the number of vouchers being less than or equal to 50.

    If there are 50 or more vouchers, the function will end. IF not, it will allow the function to continue. Then, place your put code below the pre condition.
    [Screen Shot 2022-04-20 at 2.22.14 PM.png][Screen Shot 2022-04-20 at 2.20.28 PM.png][Screen Shot 2022-04-20 at 2.19.59 PM.png]
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    Hey Rand - a quick solution could be to:
    1.  Query All Records, change return type to count
    2. Precondition, set so the count less than or equal to 50
    3. The rest of your function stack logic.


    This way you can stop execution if the count reaches 50 
  • Rand
    Rand Member
    Options
    Awesome, thank you both!