Abort model's query only if all conditions have no rows in source model

  • 2
  • Problem
  • Updated 1 year ago
Archived and Closed

This conversation is no longer open for comments or replies and is no longer visible to community members. The community moderator provided the following reason for archiving: duplicate question as https://community.skuid.com/skuid/topics/abort-models-query-only-if-all-conditions-have-no-rows-in-source-model

Objective: I'd like to use a single table within a single page include that, 
  1. Returns the opportunities for a given account when passed an account Id
  2. Returns the opportunities for a given contact when passed a contact Id (via OpportunityContactRole)
Approach: I included the XML below, but here’s a summary of the models and conditions:

1) Account model
  • Condition: Id = AccountId URL param (novaluebehavior=“noquery")
2) OpportunityContactRole model
  • Condition: Id = ContactId URL param (novaluebehavior=“noquery")
3) Opportunity model
  • Condition logic: 1 OR 2
    1. Condition 1: AccountId = Id from the Account model (novaluebehavior=“deactivate")
    2. Condition 2: Id is in the set of OpportunityId values from the OpportunityContactRoles model (novaluebehavior=“deactivate")
Problem: This works perfectly except for when both the Account model and the OpportunityContactRole model don’t have rows. In this scenario, both conditions on the Opportunity model are deactivated but the query is still executed, so we end up with a table of random opportunities. 

Changing the "novaluebehavior” of the conditions on the Opportunity model from “deactivate” to “noquery” doesn’t work either because the query gets aborted if one of the first two models doesn’t have rows, which will always be the case.

XML:

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
    <models>
        <model id="Account" limit="1" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="Account">
            <fields>
                <field id="Id"/>
                <field id="Name"/>
            </fields>
            <conditions>
                <condition type="param" value="AccountId" field="Id" operator="=" enclosevalueinquotes="true" novaluebehavior="noquery"/>
            </conditions>
            <actions/>
        </model>
        <model id="OpportunityContactRoles" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="OpportunityContactRole">
            <fields>
                <field id="ContactId"/>
                <field id="Contact.Name"/>
                <field id="OpportunityId"/>
                <field id="Opportunity.Name"/>
            </fields>
            <conditions>
                <condition type="param" value="ContactId" field="ContactId" fieldtargetobjects="Contact" operator="=" mergefield="Id" novaluebehavior="noquery" enclosevalueinquotes="true"/>
            </conditions>
            <actions/>
        </model>
        <model id="Opportunities" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="Opportunity">
            <fields>
                <field id="AccountId"/>
                <field id="Account.Name"/>
                <field id="Id"/>
                <field id="Name"/>
            </fields>
            <conditions logic="1 OR 2">
                <condition type="modelmerge" value="" field="AccountId" fieldtargetobjects="Account" operator="=" novaluebehavior="deactivate" model="Account" enclosevalueinquotes="true" mergefield="Id" state=""/>
                <condition type="modelmerge" value="" field="Id" operator="in" model="OpportunityContactRoles" enclosevalueinquotes="true" mergefield="OpportunityId" novaluebehavior="deactivate" state="" fieldtargetobjects="Opportunity"/>
            </conditions>
            <actions/>
        </model>
    </models>
    <components>
        <skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="Account" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-1JToFP-649">
            <fields>
                <field id="Id" hideable="true" uniqueid="fi-1JTyCd-752"/>
                <field id="Name" hideable="true" uniqueid="fi-1JTyCd-753"/>
            </fields>
            <rowactions/>
            <massactions usefirstitemasdefault="true"/>
            <views>
                <view type="standard"/>
            </views>
        </skootable>
        <skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="OpportunityContactRoles" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-1JTpys-663">
            <fields>
                <field id="ContactId" hideable="true" uniqueid="fi-1JTztw-762"/>
                <field id="OpportunityId" hideable="true" uniqueid="fi-1JTztw-763"/>
            </fields>
            <rowactions/>
            <massactions usefirstitemasdefault="true"/>
            <views>
                <view type="standard"/>
            </views>
        </skootable>
        <skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" alwaysresetpagination="false" createrecords="false" model="Opportunities" buttonposition="" mode="readonly" allowcolumnreordering="true" responsive="true" uniqueid="sk-1JTr2b-677">
            <fields>
                <field id="Id" hideable="true" uniqueid="fi-1JU0Bn-774" valuehalign="" type=""/>
                <field id="AccountId" hideable="true" uniqueid="fi-1JU0Bm-772"/>
                <field id="Name" hideable="true" uniqueid="fi-1JU0Bn-773"/>
            </fields>
            <rowactions/>
            <massactions usefirstitemasdefault="true"/>
            <views>
                <view type="standard"/>
            </views>
        </skootable>
    </components>
    <resources>
        <labels/>
        <javascript/>
        <css/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>
Photo of Will Soupcoff

Will Soupcoff

  • 734 Points 500 badge 2x thumb

Posted 1 year ago

  • 2

There are no replies.

This conversation is no longer open for comments or replies.