Unable to update UI-Only field in Aggregate Model

Pat VachonPat Vachon 💎💎💎
edited June 25, 2020 in Questions
I'm attempting to calculate % of opps in drawer of opps.

image

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});          });      });  });

Comments

  • Mark DeSimoneMark DeSimone 🛠️ 
    edited June 25, 2020
    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? 

    image


    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>
  • Pat VachonPat Vachon 💎💎💎
    edited May 23, 2018
    I have been able to fix this issue. Not sure what the issue was anymore though. :/ Way past this point now.
  • Mark DeSimoneMark DeSimone 🛠️ 
    edited May 23, 2018
    Well, I'm glad you were able to resolve this at the very least.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!