Record count in tab names for multiple models

  • 2
  • Question
  • Updated 2 years ago
  • Answered
  • (Edited)
Hi, I have multiple related lists organized into tabs on my Skuid Account page and I like to include the number of records located inside each tab so that users can quickly see how many records are in a tab without clicking on it. I do this by putting the following in the tab custom label 

({{$Model.Contacts.data.length}})

This produces a tab that shows Contacts (3) in the tab name. My question is; if I have a tab with multiple models inside of it. ie. a Notes and attachments tab, what is the best way that I sum those together to produce one number for my tab label.

ie. if I have 4 notes and 6 attachments for an account, how can I sum ({{$Model.Notes.data.length}}) and ({{$Model.Attachments.data.length}}) to produce "Notes & Attachments (10)" in the tab label.
Photo of Dave Dewan

Dave Dewan

  • 460 Points 250 badge 2x thumb

Posted 2 years ago

  • 2
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
You should be able to do a UI only field that adds the lengths together, then reference that field in your tab name.
Photo of Owen Smith

Owen Smith

  • 194 Points 100 badge 2x thumb
Dave - were you able to make Raymond's suggestion work?

I have been trying to accomplish the same thing with no luck. I tried creating a UI only formula field (numbe format) to add together the lengths of two data models but when I used {{Model.ModelName.data.0.length}} the page won't load at all. I tried some other ideas like:

0+{{Model.ModelName.data.0.length}}

and

{{Model.ModelName.data.0.length}}+0

When I use the same syntax in a Rich Text element I do get the length of each data model like so:

Model 1 = 12 rows
Model 2 = 18 rows

I also attempted the process discussed on this post:
https://community.skuid.com/skuid/top...

This allowed me to "add" to the two data sets together but it returned "1218" rather than "30".

Any ideas on where I might be going wrong?
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Try a dollar sign in front of model:
{{$Model.ModelName.data.0.length}}
Photo of Owen Smith

Owen Smith

  • 194 Points 100 badge 2x thumb
sorry. I had 2 typos in my comment. I do have the dollar signs in the syntax and i do not have "data.0.length" but rather "data.length" like this:

{{$Model.ModelName.data.length}}
(Edited)
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Try wrapping each with VALUE:
VALUE( {{Model.ModelName.data.0.length}})

Also, make sure that the model the UI only field is in loads AFTER the model you are referencing in this formula.
Photo of Owen Smith

Owen Smith

  • 194 Points 100 badge 2x thumb
That worked like a charm. I was going wrong on both points you made. Thanks so much for the help!
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Great, you are welcome!
Photo of Owen Smith

Owen Smith

  • 194 Points 100 badge 2x thumb
Raymond , I found a small wrinkle...

If the count from "Model 1" is 5 and the count from "Model 2" is 7, then I get the correct value of 12 when summing the two models. However, if the count from "Model 1" is 5 and the count "Model 2" is null/zero then the formula does not produce a result.

Is there a way to evaluate this?

I referenced this post but did not have much luck.
https://community.skuid.com/skuid/top...

I tried these options as well to evaluate null/zero and produce a 0:

IF({{$Model.Model1.data.length}}==null,0,VALUE({{$Model.Model2.data.length}}))

IF({{$Model.Model1.data.length}}==0,0,VALUE({{$Model.Model2.data.length}}))

IF({{$Model.Model1.data.length}}>0,VALUE({{$Model.Model2.data.length}}),0)

Is this a limitation of skuid or is there a way to evalute?
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Pat is pretty handy with Skuid and he reported a problem with formula fields not handling null values in this post:
https://community.skuid.com/skuid/top...

There was no response from Skuid support.
I would report it as a problem as a community post and see what they say.
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Pat found syntax that worked for Nulls. See this post.
https://community.skuid.com/skuid/top...
Photo of Owen Smith

Owen Smith

  • 194 Points 100 badge 2x thumb
That did it.  Thanks so much Raymond and Pat.