0

Custom maxId reset after 200

Hello,

i've set my records to automatically assign a custom record number +1 at each new record using the formula:

let t := this;
let maxId := max((select 'Storage Clients').'ID Pratica n.');
t.('ID Pratica n.' := maxId + 1)

I would need to know how i can set the maxId to rest after 200 records.

Thanks for ythe help!

8 replies

null
    • CLD
    • Valerio
    • 3 yrs ago
    • Reported - view

    or even reset at the end of the day would be a solution

    • Alain_Fontaine
    • 3 yrs ago
    • Reported - view

    One option could be to build the needed serial number by using the record reference number, the numeric part of the automatically created record identifier. I mean something like:

    let n := number(Id) - 1;
    'ID Pratica n.' := 1 + n - floor(n / 200) * 200

    • CLD
    • Valerio
    • 3 yrs ago
    • Reported - view

    thanks Alain for the reply.

    i've set my inital formula in the TRIGGER ON CREATE section. Where should i set the formula you suggested? 

    not very handy with coding.... i would need to understand exactly how and where i should write this 

    Thanks!

    • Alain_Fontaine
    • 3 yrs ago
    • Reported - view

    It should work in the same place, Trigger on create. Another possibility would be to make "ID Pratica n." a formula field, defined as:

    let n := number(Id) - 1;
    1 + n - floor(n / 200) * 200

    • CLD
    • Valerio
    • 3 yrs ago
    • Reported - view

    LOOKS GREAT. THE ONLY PROBLEM IS THAT LINKING IT TO number(Id) if i delete the record because of errors during the filling procedure it jumps to the following record therfore i lose 1 record number

    • CLD
    • Valerio
    • 3 yrs ago
    • Reported - view

    it acts with the same logic of Ninox Id Number..

    • Alain_Fontaine
    • 3 yrs ago
    • Reported - view

    Solutions based on the Ninox Id are robust, since it is guaranteed to be unique and never reused. But if you delete a record, its number is of course lost forever, per the non-reuse.

    A less robust solution, but without missing numbers, would be to put this as the "Trigger on create" function definition:

    let n := last((select Table1).'ID Pratica n.');
    'ID Pratica n.' := 1 + n - floor(n / 200) * 200

    It uses the "last" function instead of "max" but, since the records found by the "select" command are ordered by Id by default, it should work pretty reliably.

    • CLD
    • Valerio
    • 3 yrs ago
    • Reported - view

    thanks Alain! I will give it a try

Content aside

  • 3 yrs agoLast active
  • 8Replies
  • 618Views