How do I populate a model if it has just been required and has zero rows?

  • 1
  • Question
  • Updated 3 years ago
When a model is loaded for the first time it can be set to create a new record if no records match the criteria.

I have a situation where I am re-querying a record and after that re-query I would like to create a new row if the model is empty. What is the best way to accomplish this.
Photo of Joseph Ucuzoglu

Joseph Ucuzoglu

  • 1,074 Points 1k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
How about a model action that creates a new row on requery?
Photo of Joseph Ucuzoglu

Joseph Ucuzoglu

  • 1,074 Points 1k badge 2x thumb
The challenge I am running into is I only want one row in the model. Either the row it returns or the blank one if empty. I went ahead and added the new row on requery and now if the model query returns blank it works perfectly in that I see the blank fields and can enter a new value.

The problem is if there is already a match then I see the matched record and then I see the blank record pop up which I don't want.

Are there conditions available for actions like there is for rendering or some clever way to only run a particular action if a model has 0 rows for example.
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
I assume that the model "Create default row if Model has none" option only applies to the first query.

How about running a Skuid JavaScript snippet on Model Requery.  You could test whether the model is empty and create a row if it is. 
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
I think Irvin's solution is your only option to get exactly what you want. You can probably get 90% of the way there by requiring the user press a button to add a new row. Likely not a huge difference in the work flow.
Photo of Joseph Ucuzoglu

Joseph Ucuzoglu

  • 1,074 Points 1k badge 2x thumb
Thank you Raymond and Irvin. For the short term I am going to go with adding the button to the work flow and rendering it when there are 0 rows which I agree should do the trick.