Hello I have a number field (with in a model and a form) I want this field to default to the last number entered in the table. the field is a incremental number (or should be) and if I allow manual insertion of a record i don't want a repeating value, I want the next value.
I have placed this into the default field (also see screenshot)
{{parseInt(MaxPetId.data)}}
MaxPetData is a query which is based below
select max(pet_id) from pets.junk_pets_20230113 where customer_id = {{table1.selectedRow.data.id}}
so it should link to the selected row and return the max value
But it returns 0
I fixed the issue. I ensured the DB query had a alias in this case last_id (see below) select max(pet_id)+1 last_id from pets.junk_pets_20230113 where customer_id = {{table1.selectedRow.data.id}}
then in the number element, under default value referred to the alias, and this worked.
Hope this helps somebody else. {{parseInt(MaxPetId.data.last_id)}}
I made the element read only, and when I submit this to the DB it creates my next sequence. I could have done it in DB level, but this was a good learning case.