Skip to main content

I have object Case.
Case has child object Experience

I want to show Case field “order number” if any experiences attached to the case have the field “show order number” checked as true.

The current render I can find only checks the first row. I need js to check all rows.

Hey, Brandon,
To do this, first you’ll need to include the child relationship for the Experience object in the Case model, if you haven’t done so already. This tutorial explains how to do this:
http://help.skuid.com/m/models-conditions-filters/l/102520-include-child-relationships

Your snippet would be called as a custom field renderer on the Order Number field, and would look something like this:


var CHILD_RELATIONSHIP_NAME = 'Experiences__r', // Replace with the name of your child relationship CHILD_FIELD_NAME; // Replace with the name of the field on the child relationship you want to reference var field = argumentse0], value = argumentse1], $ = skuid.$, caseModel = field.model, caseRow = field.row, experiences = s]; // Get the experiences child relationship if (caseModel.getFieldValue(caseRow, CHILD_RELATIONSHIP_NAME)) { experiences = caseModel.getFieldValue(caseRow, CHILD_RELATIONSHIP_NAME).records; } // Loop through child records; check if the "Show Order Number" field is true for any of them var showOrderNumber = false; if (experiences.length > 0) { $.each(experiences, function(i, record) { if (record.CHILD_FIELD_NAME === true) { showOrderNumber = true; } }); } if (showOrderNumber === true) { // Run the standard field renderer skuid.ui.fieldRenderersrfield.metadata.displaytype]yfield.mode](field,value); } else { // Do nothing }


Let me know how that works.
Emily


I created the snippet and attached it to the Case Order_Number. I set field renderer to this javascript under “Custom (run a Snippet)”


The page loads, however order number is showing when it shouldn’t. No experiences have a true “Order_Number_Show__c” .


var CHILD\_RELATIONSHIP\_NAME = 'Experiences\_\_r', // Replace with the name of your child relationship Order\_Number\_Show\_\_c; // Replace with the name of the field on the child relationship you want to reference var field = arguments 0], value = arguments 1], $ = skuid.$, caseModel = field.model, caseRow = field.row, experiences = r]; // Get the experiences child relationship if (caseModel.getFieldValue(caseRow, CHILD\_RELATIONSHIP\_NAME)) { experiences = caseModel.getFieldValue(caseRow, CHILD\_RELATIONSHIP\_NAME).records; } // Loop through child records; check if the "Show Order Number" field is true for any of them var showOrderNumber = false; if (experiences.length \> 0) { $.each(experiences, function(i, record) { if (record.Order\_Number\_Show\_\_c === true) { showOrderNumber = true; } }); } if (showOrderNumber === true) { // Run the standard field renderer skuid.ui.fieldRenderersdfield.metadata.displaytype]sfield.mode](field,value); } else { // Do nothing }

Is this code only going to showOrderNumber on non-deleted experiences related to the case?


Brandon,
First, I think I gave you some bad JS. Update the first part of your code with this:


var CHILD_RELATIONSHIP_NAME = 'Experiences__r', // Replace with the name of your child relationship<br>

CHILD_FIELD_NAME = 'Order_Number_Show__c'; // Replace with the name of the field on the child relationship you want to reference

And replace


if (record.Order_Number_Show__c === true)


with

if (record[CHILD_FIELD_NAME] === true)

In that code, you will want to replace ‘Order_Number_Show__c’ with the API name of the “Show Order Number” checkbox field you were referring to earlier on your child relationship. Does that make sense?

Thanks!
Emily


Reply