I need to put child names into a text field

  • 1
  • Question
  • Updated 3 years ago
  • Answered
So I can display child record names separated by comma in the child-template filed that you can drag in from the field menu of the model, but I need that exact information to be populated into a text field. I don't need formatting, just the info. How can you get a list of child names separated by comma into a plain text field? Thanks
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Here's an idea, you can select a child relationship on a model under the "Fields" section. Select your child relationship and set up a field renderer snippet. This may not be so efficient but it'll probably work...


var field = arguments[0],	
    value = arguments[1],    
    $ = skuid.$,
    row = field.row
    Id = row.Id;
var str = "";
$.each(row.ChildRelationship.records, function(i, rec){
    if(rec.ParentId == Id){
        str += rec.Text_Field__c + ","
    }
});
value = str;
//render field etc...
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Thanks Moshe! I'm not a strong coder, but I couldn't get this code to work. It breaks the page.
It seems like I could do this through a model action.:
Every time the model is queried or saved or a new row created update row in model. I tried it, but the text field stays empty. I'm thinking I may not be using the right merge text. This is what displays in the child template that I dragged from the field menu.: {{Chronic_Condition__r.Name}}
Can I set a text field equal to this using an action? If so what merge text would I use?
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Try some console.log()'s to see what you're getting. I belive that your loop should look like this:

$.each(row.Chronic_Condition__r.records, function(i, rec){
console.log(rec);
    if(rec.ParentId == Id){
        str += rec.Name + ","
    }
});
console.log(str);


etc... also replace ParentId with the correct API Name
(Edited)
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Thanks again, Moshe. As always, I appreciate everyone's help. After a bunch of searches on the community, I came across this post:
https://community.skuidify.com/skuid/...
I added a model action that updates my text field with the child reference illustrated in this post and it works beautifully. Thanks!
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,026 Points 20k badge 2x thumb
Glad to hear that you got it working! 
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
I used to code Matt wrote for referencing a single record, then strung together five of those so I could get five comma separated values. I couldn't t get the following code to work if I have to reference the model. I want to use it in a template in a table of a different model.
If you could tell me how to reference a child record set from outside the model, that would be helpful for future uses. Thanks!
{{#EventRelations.records}}{{Relation.Name}}
{{/EventRelations.records}}