Late loading a model isn't working with cross-model conditions

edited March 2, 2017 in Questions
I'm having a problem when I have a model that I set to late load (not on page load).  I'm setting a condition in a snippet, and then tell the model to update ... and that works just fine.  But other models that have relationships to the first model (such as a primary model of Lead, and a secondary related model with a condition of Task.WhoId == Lead.Id) do not update their content (they are also set to late load).

I'm making sure to call updateData, I'm waiting for Lead to load before trying to load Task, and yet I still find the Task object doesn't work.  If I switch to setting the condition manually (where I simple call Model.setCondition and use Lead.data[0].Id from the Lead model) it works fine.

I've created a very simple example of this problem.  Note that I am using RC3 of Superbank ... and I've not tried it on any other release.  This sample code uses a hard-coded Id of a Lead object - so you will need to adjust that for your own Lead objects.

Any thoughts on what I'm doing wrong?

Thanks,

- Chris
<skuidpage unsavedchangeswarning="yes" showsidebar="true" showheader="true">   <models>
      <model id="Lead" limit="20" query="false" createrowifnonefound="false" sobject="Lead" doclone="" type="">
         <fields>
            <field id="Id"/>
            <field id="Name"/>
         </fields>
         <conditions>
            <condition type="fieldvalue" value="" field="Id" operator="=" novaluebehavior="noquery" state="filterableon" inactive="false" name="Id" enclosevalueinquotes="true"/>
         </conditions>
         <actions/>
      </model>
      <model id="Task" limit="20" query="false" createrowifnonefound="false" sobject="Task" doclone="" type="">
         <fields>
            <field id="CreatedDate"/>
            <field id="CallType"/>
            <field id="Subject"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="WhoId" operator="=" model="Lead" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="noquery" state="filterableon" inactive="false" name="WhoId"/>
         </conditions>
         <actions/>
      </model>
   </models>
   <components>
      <basicfieldeditor showheader="true" showsavecancel="false" model="Lead" buttonposition="" mode="readonly" layout="">
         <columns>
            <column width="100%">
               <sections>
                  <section title="Section A" collapsible="no">
                     <fields>
                        <field id="Name" valuehalign="" type=""/>
                     </fields>
                  </section>
               </sections>
            </column>
         </columns>
      </basicfieldeditor>
      <skootable showconditions="true" showsavecancel="false" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="false" model="Task" buttonposition="" mode="readonly">
         <fields>
            <field id="CreatedDate" valuehalign="" type=""/>
            <field id="CallType" valuehalign="" type=""/>
            <field id="Subject" valuehalign="" type=""/>
         </fields>
         <rowactions/>
         <massactions usefirstitemasdefault="true"/>
         <views>
            <view type="standard"/>
         </views>
      </skootable>
   </components>
   <resources>
      <labels/>
      <javascript>
         <jsitem location="inline" name="setupId" cachelocation="false" url="">var $ = skuid.$;
$(document.body).one('pageload',function() {
    var lead = skuid.model.getModel('Lead');
    var task = skuid.model.getModel('Task');
    var leadCondition = lead.getConditionByName('Id');
    var taskCondition = task.getConditionByName('WhoId');
    
    lead.setCondition(leadCondition, '00Q70000011wqoiEAA', false);
    lead.updateData((function(){
//        If the following line is added, it works fine (which even loads the Id from the lead model)
//        task.setCondition(taskCondition, lead.data[0].Id, false);
        task.updateData();        
    }));
});
</jsitem>
      </javascript>
      <css/>
   </resources>
</skuidpage>

Comments

  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited March 2, 2017
    Chris,

    Try doing a multi-model updateData() call -- that should eliminate the need to do an intermediary setCondition:

    skuid.model.updateData([lead,task]);

    This makes a difference because when both Models are being processed server-side concurrently, Skuid can re-evaluate "field from another Model" conditions because the "other Model" exists for Skuid to use it.
  • edited March 2, 2017
    Ahhh...  I missed that static method!  That makes great sense, and it appears to work.  Thanks as always!

    P.S. Superbank is working great in production (internal use plus SFDC community).  24 hours and no problems reported from field!
  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited December 21, 2016
    Glad to hear it! 
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!