Access child relationships through merge syntax

  • 1
  • Question
  • Updated 11 months ago
  • Answered
Is it possible to access child relationship through merge syntax? I have tried a few variations with no success. I am trying to write the value from the child relationship to a new object.

The last attempt looks like this:

{{$Model.NYItemMaster.data.0.SCMC_InventoryItems__r.SCMC__Condition_Code__r}}
Photo of Tami Lust

Tami Lust

  • 5,280 Points 5k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
To get a field off of a particular child relationship record:

{{$Model.NYItemMaster.data.0.SCMC_InventoryItems__r.records.0.SCMC__Condition_Code__r}}
Photo of Tami Lust

Tami Lust

  • 5,280 Points 5k badge 2x thumb
I tried what you suggested but I have not been able to get it to fill in the condition code field. 

I have a model entitled NYItemMaster from this model I want to copy certain values to a sales order lines model.

NYItemMasters has a child relationship to Inventory_Items. There is a condition code lookup field in Inventory Items to an object condition code. I need to copy that value to the SalesOrderLines model.

Sales Order Lines has a field entitled condition code that looks up to the same condition code object. 

So far I can not get this to work through the child relationship with the merge syntax provided. Can you see what I am doing wrong?

Here is what my code currently looks like:
{{$Model.NYItemMaster.data.0.SCMC_InventoryItems__r.records.0.SCMC__Condition_Code__r.Id}}
Thank you for any light you can shed.
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Did you actually request the SCMC__Condition_Code__r.Id field on your Child Relationship fields? Try just getting the Condition Code lookup field value itself, assuming that you've added SCMC__Condition_Code__c to the list of fields requested for your Child Relationship:

{{$Model.NYItemMaster.data.0.SCMC_InventoryItems__r.records.0.SCMC__Condition_Code__c}}
Photo of Tami Lust

Tami Lust

  • 5,280 Points 5k badge 2x thumb
Zach,

Thank you for your reply. The issue was what I was trying to access not how. I had to access the information in another way. 

Thank you for letting me know how to access the child relationship fields. This will be helpful in the future.
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Zach,
I want to display multiple records of the parent in a table. I want to display a field of the first child record (row 0) from EACH of the parent records as a template field in the table. When I use your formula above, it works, but it loses the context of the parent row so I only get the first child row of the FIRST PARENT record. How can I get it to hold context so that each parent row displays the first child record of that parent?
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Disregard. I got it. Continuing with Tami's use case, the formula would be:
{{SCMC_InventoryItems__r.records.0.SCMC__Condition_Code__c}}