Skip to main content

Is there any way to get the count of the child records for the parent record in context? For example, I need to know the number of the Quote child records for the current Opportunity in context. Any way to achieve this declaratively?

Yep, you can definitely do this declaratively! Just make sure you include the child relationship in the model and then you can use


{{Quote.records.length}} (or Quote__r if it’s a custom object) in a text component or template field.


Check out the solo adventure at the end of the Skuid Skool course Configure Model Fields for an example


Also there’s a merge syntax cheat sheet in this course: Magical world of Merge Syntax


See also
https://docs.skuid.com/v16.0.7/v2/en/skuid/merge-syntax/#merge-variables


Hi @Anna_Wiersema ,


Thank you so much for your response. Learnt something new today 🙂


However, I am also using some models based on REST data source and have established relationship via a text field. You can think of it as two models where one of them is a parent model and the another one is a child model. Each record in the child model has a ParentId field (text field) which is populated with the Id of the related parent, this Id is the unique Id which Skuid generates. For each row in the parent model, I want the number of child rows.


Any suggestions to implement this?


I think the most reliable way to produce this output would be to build it within your endpoint, so that the parent endpoint includes the count of child records (an aggregate).


But knowing this is not always possible, I think your best bet will be a snippet that iterates through the rows of the child model, and for each row, uses the parent ID to determine a value to update (+1) or creates a new value. Once you have iterated through the rows - you can push these aggregate counts into a UI only field on the parent model.


Reply