Template repeating child relationship data in table

  • 2
  • Problem
  • Updated 4 years ago
  • Solved
  • (Edited)
I'm using a field form a child relationship to the model and am including it in a table via template. The data being returned is duplicating itself though. I've attached what is going on. How the template is set and the results. Any help is appreciated.
Photo of Greg Thomson

Greg Thomson

  • 130 Points 100 badge 2x thumb

Posted 4 years ago

  • 2
Photo of Louis Skelton

Louis Skelton

  • 4,878 Points 4k badge 2x thumb
Have you tried using three curly braces instead?

{{{Field_Name}}}

Sometimes that fixes these sorts of issues as it removes the field formatting - if not, I'm sure someone else will point you in the right direction!
Photo of Greg Thomson

Greg Thomson

  • 130 Points 100 badge 2x thumb
Three curly braces still does the same thing.
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
If there are multiple child rows in the child model, a template field will display a value for every row. Do you only want to see it once? You can probably do that with Javascript.
Photo of Greg Thomson

Greg Thomson

  • 130 Points 100 badge 2x thumb
Moshe - Yep, shooting for seeing it once.
Photo of Louis Skelton

Louis Skelton

  • 4,878 Points 4k badge 2x thumb
If the document name of the child record is always the same could you pass it up to the parent using a cross-object workflow and then just use the parent field in the table? I guess that's not particularly elegant...
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
OK try something like this:
1) Drag a random text field into the table, hook up a custom field renderer javascript snippet.
2) In the snippet code like so:

var field = arguments[0],    
    value = arguments[1],
   $ = skuid.$;
// this should be your child relationship model
var yourModel = skuid.$M('YOURMODELNAME');
var yourFirstRow = yourModel.getFirstRow();
value = yourModel.getFieldValue(yourFirstRow,'c2g__Invoice__r.Name');
skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Moshe's way would work, but you'd have to create a separate model for your child rows.  It looks like right now you're using a Child Relationship field.  The way your data model is set up seems a little strange, but if it needs to be that way, I'd take this approach...

Instead of dragging a Child Relationship field into your table, just drag a plain old template component in there.  For your template text, use...

{{c2g__Invoice__r.records.0.Name}}
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Also, if you're only using the first Child Relationship record returned, I'd make sure to set the "Max # of Records (Limit)" to 1.  This way your page will be as efficient as possible.
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Agreed with Ben, the best way to do this would be to set the "Max # of Records (Limit)" to 1 on your Child Relationship, from its "Properties" area. Then you don't have to drag in a Template, you can just go back to dragging in a regular Child Relationship, which is a little simpler to work with.
Photo of Greg Thomson

Greg Thomson

  • 130 Points 100 badge 2x thumb
Ben - your answer took care of it. Thank you. And thank you to others for your help.
Photo of Milind Gupte

Milind Gupte

  • 110 Points 100 badge 2x thumb
Somewhat related question.  I have also posted a separate question for this but may be you can help.

I am trying to set a condition on the Child Relationship field.  This is in addition to limiting the number of records to 1.  My condition works if I set it by specifying a specific value for <= condition.  But if I use this to compare against a field from a source model it does not work.  Looks like the source model does not get evaluated in time.  The same source model does return a record and I have verified that by just associating that field in a field editor.  But the child condition does not work since source model apparently returns 0 records.

Any ideas?
Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Hi, Milind,
So, if I understand correctly, you have a parent model and child model, and the parent model has a condition where Id = the lookup field in any row returned by the child model. In your list of models, is the child model (the source model) listed before the parent model?
Emily
Photo of Milind Gupte

Milind Gupte

  • 110 Points 100 badge 2x thumb
Thanks for the reply.  I did figure that out and it started working when the model that provides the rows for a condition is listed before the model that uses the condition.

The only problem that remains is when I update the source model that provides rows for a condition in a chidlrelationship field in another model it does not automatically use the updated rows from the source model even when I query the model again using action framework.

Looks like the condition defined using “user rows from source model” only sets it initially.  If the source model changes it does not update the condition.  I could write a small java script code to force that when my source model changes but I was assuming that requerying the model would make sure that the conditions are also reevaluated using the updated source or at least there is a way to force it in action framework.

May be you can consider it as an item for Action FW enhancement.

Thank you

Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Milind,
I think another one of our other customers just brought up a similar issue! It looks like this is a bug, and one of our product developers has looked into it. Requerying the model should definitely update the data to reflect the updated condition. One thing to note: If you don't need your model data directly on page load, I think the models may actually work correctly if you set "Load model data on page load" to false for these models, and then query them when you need them? Not ideal, but it might be a workaround for now. Thanks for reporting this!
Emily