Unable to update UI-Only field in Aggregate Model

  • 1
  • Problem
  • Updated 6 months ago
  • Solved
I'm attempting to calculate % of opps in drawer of opps.



A field renderer doesn't work because I can only run the code once the context for the table has been applied for all rows to make renderedlist complete.

This snippet seemingly is good to go except the updateRow function does nothing.
var params = arguments[0],
    OppsBySPByStageDrawerTable = skuid.$M('OppsBySPByStageDrawerTable'),
    models = [OppsBySPByStageDrawerTable],
    listSum,
	$ = skuid.$;

// loop through all models used in drawers to update their percentOfOpps within drawer
$.each(models, function(m,model){
    
    $.each(model.registeredLists, function (l,list){
        listSum = 0;    
        $.each(list.visibleItems, function(i,item){
            listSum = listSum + item.row.countId;
        });
        $.each(list.visibleItems, function(i,item){
            model.updateRow(item.row,{percentOfOpps: item.row.countId / listSum});
        });
    });
});
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb

Posted 6 months ago

  • 1
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Hi Pat,

I'm able to use your snippet in my simple aggregate model on Opps. Here's a screenshot. I'm firing the snippet using an event-triggered action sequence with the Skuid: Page rendered event. Could it be that your snippet isn't running at the right time in the pageload process? 




Here's my XML, if you'd like to test in your org:

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
    <models>
        <model id="OppsBySPByStageDrawerTable" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" sobject="Opportunity" type="aggregate">
            <fields>
                <field id="percentOfOpps" uionly="true" displaytype="DOUBLE" label="percentOfOpps" ogdisplaytype="TEXT" precision="9" scale="2"/>
                <field id="Id" name="countId" function="COUNT"/>
            </fields>
            <conditions/>
            <actions/>
            <groupby method="simple">
                <field id="Account.Name" name="accountName"/>
                <field id="AccountId" name="accountId"/>
            </groupby>
        </model>
    </models>
    <components>
        <skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" hideheader="false" hidefooter="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="OppsBySPByStageDrawerTable" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-2460-255">
            <fields>
                <field id="Account.Name" name="accountName" hideable="true" uniqueid="fi-2460-292"/>
                <field id="Id" name="countId" hideable="true" uniqueid="fi-2460-268"/>
                <field id="percentOfOpps" name="percentOfOpps" hideable="true" uniqueid="fi-2460-269"/>
            </fields>
            <rowactions/>
            <massactions usefirstitemasdefault="true"/>
            <views>
                <view type="standard"/>
            </views>
        </skootable>
    </components>
    <resources>
        <labels/>
        <javascript>
            <jsitem location="inlinesnippet" name="newSnippet" cachelocation="false">var params = arguments[0],
    OppsBySPByStageDrawerTable = skuid.$M('OppsBySPByStageDrawerTable'),
    models = [OppsBySPByStageDrawerTable],
    listSum,
$ = skuid.$;
// loop through all models used in drawers to update their percentOfOpps within drawer
$.each(models, function(m,model){
    
    $.each(model.registeredLists, function (l,list){
        listSum = 0;    
        $.each(list.visibleItems, function(i,item){
            listSum = listSum + item.row.countId;
        });
        $.each(list.visibleItems, function(i,item){
            model.updateRow(item.row,{percentOfOpps: item.row.countId / listSum});
        });
    });
});</jsitem>
        </javascript>
        <css/>
        <actionsequences uniqueid="sk-2460-227">
            <actionsequence id="0bd48eab-e546-4aae-88f6-dfbff02fface" label="Pageload" type="event-triggered" event-scope="component" event-name="page.rendered">
                <description/>
                <actions>
                    <action type="custom" snippet="newSnippet"/>
                </actions>
            </actionsequence>
        </actionsequences>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
I have been able to fix this issue. Not sure what the issue was anymore though. :/ Way past this point now.
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Well, I'm glad you were able to resolve this at the very least.