concatenate distinct text fields from child Records

Correct, Bk statement is a child of account

Yes, Both bk_statements and bk_statements_AGG Models are based on SF custom object Bank_statement

I tried the following:

From Bk_Statements model & bk_statements_AGG, in fields, went to Account relationship , but the Account UI field (Named UniqueBankName) not showing up in that list

Then tried Via UI Formula Field On Both Models ( Bk_Statements model & bk_statements_AGG) with “insert field” function

Then tried via Model Lookup function in UI field on both models (this part, I’m not sure i got syntax or proper lookup values correctly

MODEL_LOOKUP(“ModelName”,“FieldNametoBeReturned”,“FieldNameToMATCHinCurrentModel”,{{MatchingValueFromCurrentModel}})

MODEL_LOOKUP(“Account”,“UniqueBankName”,“FieldNameToMATCHinCurrentModel”,{{MatchingValueFromCurrentModel}})

Not sure what these 2 parameters should be replaced with: “FieldNameToMATCHinCurrentModel”,{{MatchingValueFromCurrentModel}}). I tried a result field in AGG and tried a bunch of other things, but no idea lol

The reason I assumed you had to do the snippet on the account model, is that that’s the only thing that group those records together.
But technically the place where I need the distinct names, is the Bk Agg model ( i do not need it on account)

Hope it’s clearer and i apologize for my confusing posts lol

Dave, you can’t get to ui-only fields through relationships, as far as I know.

Instead of building your renderer to concatonate the unique names on the account object through the child relationships, let’s build it on the aggregate model.

Use your grouping field on the agg model (which I’m assuming is Account?), and add it as another column to your table. Then use a custom renderer, something like this:

var field = arguments[0],
    value = arguments[1],   // this will be your account id.
    $ = skuid.$;
var model = skuid.$M(‘bk_statements’);

// Here we’ll iterate through all the rows of your bk_statements model,
// and find the ones where the Account__c field matches the Account Id.
// (change that below if your field name is different) 

var uniquearray=;
$.each(model.getRows(), function(i,r){
if (r.Account__c == value) {    
if (uniquearray.indexOf(r.Bank_Name__c) == -1) {
        uniquearray.push(r.Bank_Name__c);
    }
}
});
var uniqueString = uniquearray.join(", ");

skuid.ui.fieldRenderers.TEXT.read(field,uniqueString);

Thx a lot Matt,

I’m trying it atm,

Now, you mentioned grouping, I do not have any grouping on that agg model, just a condition:

But it seems to work correctly as is.

Here are the new issues I got

1- Realized it’s case sensitive , so Apple and APPLE , shows as 2 different results.
Not a big problem , as technically i can use a SF formula field to copy over that info and transform all into uppercase. and then run that Snippet on that field instead

2- No matter what I try , i cannot Seem to add that field as part of a template merge

If I show the field by itself (not referenced in template field) it shows fine

Now if i try to make it part of the template field above in SS (in yellow), it does not work
it’s suppose to show the names right after the last line.

-That template field is based on same model as the uniqueOnBk field (all on Bk Agg)

Here’s template merge i used:
All the merges below are UI only fields, and all work except last 1

Range: {{Start_date}} to {{End_date}}

of Statements: {{countStatementDatec}}

of unique Bank Accounts: {{countdistinctBankNameAcco}} - {{UniqueBank}}

Looked in console, i do not see any error regarding this

For now it does the job, so if busy or too complicated, it’s OK do not bother. I’ll leave it as a separate field right under that template field (like it is now)

At this point I’m more curious than anything on the reasons why i cannot make this work

Thx again!

Dave,

You can use .toUpperCase() or .toLowerCase() in javascript instead of SFDC formula field, if you want.

The issue with the template is that we’re using a field renderer to display the distinct bank names. We’re not actually saving that value to the model, so that we can access it with merge syntax. Add an updateRow() to the end of your custom renderer snippet.

Here’s a new version with both changes:

var field = arguments[0],<br />&nbsp;&nbsp;&nbsp; value = arguments[1], &nbsp; &#47;&#47; this will be your account id&#46;<br />&nbsp;&nbsp;&nbsp; $ = skuid&#46;$;<br />var model = skuid&#46;$M('bk_statements');<br />&#47;&#47; Here we'll iterate through all the rows of your bk_statements model,&nbsp;<br />&#47;&#47; and find the ones where the Account__c field&nbsp;matches the Account Id&#46;<br />&#47;&#47; (change that below if your field name is different)&nbsp;<br />var uniquearray=[];<br />$&#46;each(model&#46;getRows(), function(i,r){<br />if (r&#46;Account__c == value) { &nbsp; &nbsp;<br />if (uniquearray&#46;indexOf(r&#46;Bank_Name__c&#46;toUpperCase()) == -1) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uniquearray&#46;push(r&#46;Bank_Name__c&#46;toUpperCase());<br />&nbsp;&nbsp;&nbsp; }<br />}<br />});<br />var uniqueString = uniquearray&#46;join(", ");<br />skuid&#46;ui&#46;fieldRenderers&#46;TEXT&#46;read(field,uniqueString);<br />var AgModel = skuid&#46;$M('NAMEOFYOURMODEL'); &nbsp;&#47;&#47;If we don't already have this&#46;&#46;&#46; ?<br />AgModel&#46;updateRow(AgModel&#46;getFirstRow(), {'UniqueBank' : uniqueString});

Good morning,

The Uppercase change worked fine, tyvm

but I still cannot use that field in a template

here’s my snippet in case i misunderstood an instruction

var field = arguments[0],
    value = arguments[1],   // this will be your account id.
    $ = skuid.$;
var model = skuid.$M(‘Bank_statements’);

// Here we’ll iterate through all the rows of your bk_statements model,
// and find the ones where the Account__c field matches the Ac count Id.
// (change that below if your field name is different)

var uniquearray=;
$.each(model.getRows(), function(i,r){
if (r.Account__c == value) {   
if (uniquearray.indexOf(r.Bank_Name__c.toUpperCase()) == -1) {
        uniquearray.push(r.Bank_Name__c.toUpperCase());
    }
}
});
var uniqueString = uniquearray.join(", ");

skuid.ui.fieldRenderers.TEXT.read(field,uniqueString);

var AgModel = skuid.$M(‘Bnk_aggregate1’);  //If we don’t already have this… ?
AgModel.updateRow(AgModel.getFirstRow(), {‘UniqueBank’ : uniqueString});

Thx

Dave,
To address your template issue: the code assumes that you have a ui-only field on your Bnk_Aggregate1 model called ‘UniqueBank’.

check the console to see if that value for that model/field is updating correctly:. Just paste this line into the console: 

skuid.$M('Bnk_aggregate1').getFieldValue(skuid.$M('Bnk_aggregate1').getFirstRow(),'UniqueBank');

and see what it returns.
If that value is what you expect, but it isn’t showing up in the template, you may need to just rerender the template:

skuid.$C('MyTemplateUniqueId').render(); 

Try that in the console, if you know the value for UniqueBank is correct (replacing MyTamplateUniqueId with whatever you put as the id for your template component).

If that works, then add the render() line to the end of your custom renderer code.

Looking for my template UniqueID, I realized i was not clear by mistake

I’m trying to use it as part of a Field Template(#2 in ss below) not a template component

I just tried the “merge” in template component (#1 in ss below) , and it did render.

I should be able to work with this, so ty again.

But I’m curious to know what is the difference between both type of templates

ty :slight_smile: