Row Action Render Snippet based on value from another model

  • 1
  • Question
  • Updated 8 months ago
  • Answered
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],
    $ = skuid.$;
var selectedWorkItems = skuid.model.getModel('SelectedWorkItems');
selectedWorkItemsFirstRow = selectedWorkItems.getFirstRow();
if(selectedWorkItems.data.length === 0){
    return true;
}
if(selectedWorkItems.data.length > 0){
    if(selectedWorkItems.data[0].Site_Certification_Standard__r.Site_Certification__r.Site_Certification_Contact__r.Name === currentRow.Site_Certification_Standard__r.Site_Certification__r.Site_Certification_Contact__r.Name){
        return true;
    } else {
        return false;
    }
}
skuid.component.getById('workitem-table').render();
Any help would be greatly appreciated.
Photo of William Keam

William Keam

  • 302 Points 250 badge 2x thumb

Posted 8 months ago

  • 1
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
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}}&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>
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Bill, thank you for sharing this suggestion. I'm always glad to see declarative solutions!
Photo of William Keam

William Keam

  • 302 Points 250 badge 2x thumb
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],
$ = skuid.$;
skuid.component.getById('workitem-table').render();
var WorkItems = skuid.model.getModel('WorkItems');
WorkItems.evaluateFormulaFields();
(Edited)