Row Action Render Snippet based on value from another model

Hello everyone,

I have a table with a custom row action. I would like to render the row action based on the value from another model. The problem I am facing is I cannot work out how to get the value of the current row to compare with the value from the other field.

var params = arguments[0],<br>&nbsp; &nbsp; $ = skuid.$;<br>var selectedWorkItems = skuid.model.getModel('SelectedWorkItems');<br>selectedWorkItemsFirstRow = selectedWorkItems.getFirstRow();<br>if(selectedWorkItems.data.length === 0){<br>&nbsp; &nbsp; return true;<br>}<br>if(selectedWorkItems.data.length &gt; 0){<br>&nbsp; &nbsp; if(selectedWorkItems.data[0].Site_Certification_Standard__r.Site_Certification__r.Site_Certification_Contact__r.Name === <b>currentRow</b>.Site_Certification_Standard__r.Site_Certification__r.Site_Certification_Contact__r.Name){<br>&nbsp; &nbsp; &nbsp; &nbsp; return true;<br>&nbsp; &nbsp; } else {<br>&nbsp; &nbsp; &nbsp; &nbsp; return false;<br>&nbsp; &nbsp; }<br>}<br>skuid.component.getById('workitem-table').render();

Any help would be greatly appreciated.

William,

You may want to add a Model Formula field to the same model that drives your table. Setup the field as a Checkbox and have it return true or false based on a comparison to your other model’s data. This will take care of getting the right value in context to compare and keep you declarative.

Here is a sample page that demonstrates this:

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" useviewportmeta="true" showsidebar="true" showheader="true" tabtooverride="Opportunity">
    <models>
        <model id="CurrentUser" limit="1" query="true" createrowifnonefound="false" datasource="salesforce" sobject="User">
            <fields>
                <field id="CreatedDate"/>
            </fields>
            <conditions>
                <condition type="userinfo" value="" field="Id" operator="=" enclosevalueinquotes="true" userinfotype="userid"/>
            </conditions>
            <actions/>
        </model>
        <model id="OppStages" query="true" createrowifnonefound="false" datasource="salesforce" sobject="Opportunity" type="aggregate">
            <fields/>
            <conditions/>
            <actions/>
            <groupby method="simple">
                <field id="StageName" name="stageName"/>
            </groupby>
        </model>
        <model id="Opportunity" limit="100" query="true" createrowifnonefound="false" datasource="salesforce" sobject="Opportunity">
            <fields>
                <field id="Name"/>
                <field id="CreatedDate"/>
                <field id="StageName"/>
                <field id="RenderAction" uionly="true" displaytype="FORMULA" label="RenderAction" ogdisplaytype="TEXT" readonly="true" returntype="BOOLEAN">
                    <formula>IF({{CreatedDate}}&amp;gt;{{$Model.CurrentUser.data.0.CreatedDate}}, true, false)</formula>
                </field>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="" enclosevalueinquotes="true" field="StageName" operator="=" state="filterableoff" inactive="true" name="StageName"/>
            </conditions>
            <actions/>
        </model>
    </models>
    <components>
        <pagetitle model="Opportunity" uniqueid="sk-2A_j-199">
            <maintitle>
                <template>{{Model.labelPlural}}</template>
            </maintitle>
            <subtitle>
                <template>Home</template>
            </subtitle>
            <actions>
                <action type="savecancel" uniqueid="sk-2A_j-197"/>
            </actions>
        </pagetitle>
        <basicfieldeditor showheader="true" showsavecancel="false" showerrorsinline="true" model="CurrentUser" uniqueid="sk-2Lfl-269" mode="read">
            <columns>
                <column width="50%">
                    <sections>
                        <section title="Current User" collapsible="no">
                            <fields>
                                <field id="CreatedDate" uniqueid="sk-2Lfl-277"/>
                            </fields>
                        </section>
                    </sections>
                </column>
                <column width="50%">
                    <sections>
                        <section title="Section B" collapsible="no">
                            <fields/>
                        </section>
                    </sections>
                </column>
            </columns>
        </basicfieldeditor>
        <skootable showconditions="true" showsavecancel="false" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Opportunity" mode="read" allowcolumnreordering="true" uniqueid="sk-2A_j-213">
            <fields>
                <field id="RenderAction" hideable="true" uniqueid="fi-2Lfl-764"/>
                <field id="Name" hideable="true" allowordering="true" uniqueid="fi-2A_c-930"/>
                <field id="StageName" hideable="true" uniqueid="fi-2A_j-255"/>
                <field id="CreatedDate" hideable="true" allowordering="true" uniqueid="fi-2A_c-931"/>
            </fields>
            <rowactions>
                <action type="edit"/>
                <action type="delete"/>
                <action type="multi" label="Conditionally Rendered Action" icon="sk-icon-config">
                    <actions/>
                    <renderconditions logictype="and">
                        <rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="Opportunity" sourcetype="fieldvalue" field="RenderAction" fieldtargetobjects="Opportunity" value="true"/>
                    </renderconditions>
                </action>
            </rowactions>
            <massactions usefirstitemasdefault="true">
                <action type="massupdate"/>
                <action type="massdelete"/>
            </massactions>
            <views>
                <view type="standard"/>
            </views>
            <filters>
                <filter type="multiselect" createfilteroffoption="true" affectcookies="false" autocompthreshold="25" conditionsource="manual" filtermethod="server" labelmode="no" condition="StageName" filteroffoptionlabel="All Stages">
                    <sources>
                        <source type="model" effectsbehavior="justdefault" model="OppStages">
                            <labeltemplate>{{{stageName}}}</labeltemplate>
                            <valuetemplate>{{{stageName}}}</valuetemplate>
                        </source>
                    </sources>
                </filter>
            </filters>
        </skootable>
    </components>
    <resources>
        <labels/>
        <css/>
        <javascript/>
        <actionsequences uniqueid="sk-2A_j-252"/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>

Bill, thank you for sharing this suggestion. I’m always glad to see declarative solutions!

Thanks Bill!

Sometimes the most simple solution is not the most apparent! I setup the formula field as you suggested. The only other thing I had to do was call a javascript snippet to evaluate the formula fields after the row is adopted into the ‘selected’ model.

var params = arguments[0],<br />$ = skuid&#46;$;<br />skuid&#46;component&#46;getById('workitem-table')&#46;render();<br />var WorkItems = skuid&#46;model&#46;getModel('WorkItems');<br />WorkItems&#46;evaluateFormulaFields();