getFirstRow() returns 'undefined' after row created and model saved

I start with an empty model. I create a row. I save the model. Then when I use getFirstRow(), it returns undefined. It looks like mC.data.length = 0, even after I’ve created a row and saved. What am I doing wrong here?

I tried re-setting the value for the model variable (mC) after the save, but it still shows data.length = 0.

Here’s my code:

// Schedule -- new case&nbsp;&nbsp;<br>&nbsp; var //mP = skuid.$M('Patient'),<br>&nbsp; &nbsp; mC = skuid.$M('Case'),<br>&nbsp; mA = skuid.$M('Open'),<br>&nbsp; rA = mA.getFirstRow(),<br>&nbsp; $ = skuid.$,<br>&nbsp; dfd = new $.Deferred();<br>&nbsp;&nbsp;<br>&nbsp; //Create Patient Case<br>&nbsp; $.blockUI({<br>&nbsp; &nbsp; &nbsp;message: 'Creating Patient Case...'<br>&nbsp; });<br>&nbsp;&nbsp;<br>&nbsp; mC.createRow({ <br>&nbsp; additionalConditions:[<br>&nbsp; {field: 'Case_Type__c', value: rA.Case_Type__c},<br>&nbsp; {field: 'LMP__c', value: rA.LMP__c},<br>&nbsp; {field: 'Preliminary_AVR__c', value: rA.Preliminary_AVR__c},<br>&nbsp; {field: 'Payment_Option__c', value: rA.Payment_Option__c},<br>&nbsp; {field: 'Permission_to_Call__c', value: rA.Permission_to_Call__c},<br>&nbsp; {field: 'Permission_to_Text__c', value: rA.Permission_to_Text__c},<br>&nbsp; {field: 'Permission_to_Leave_Message__c', value: rA.Permission_to_Leave_Message__c},<br>&nbsp; {field: 'Referral_Source__c', value: rA.Referral_Source__c}<br>&nbsp; ]<br>&nbsp; });<br>&nbsp;&nbsp;<br>&nbsp; //Save Case model<br>&nbsp; $.when(mC.save())<br>&nbsp; &nbsp; &nbsp; &nbsp; .done(function(){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Set Interaction Patient_Case__c to case just created, and query Interaction model<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mC = skuid.$M('Case');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var rC = mC.getFirstRow(),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mI = skuid.$M('Interaction');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mI.setCondition(mI.getConditionByName('CaseID'), rC.Id);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.when(mI.updateData())<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .done(function(){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfd.resolve();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .fail(function(){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Interaction model query failed.');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfd.reject();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfd.resolve();<br>&nbsp; &nbsp; &nbsp; &nbsp; })<br>&nbsp; &nbsp; &nbsp; &nbsp; .fail(function(){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Case model save failed.');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfd.reject();<br>&nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; return dfd.promise();

Hi Matt,

I had a similar issue and using this pattern worked for me:


PricebookEntriesModel.save({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp;callback: function (results) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (results.totalsuccess) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Created PricebookEntry');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pbe = PricebookEntriesModel.getFirstRow();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createLineItem(pbe);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Error creating PricebookEntry');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deferred.reject();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; });





Thanks, Irvin. I’m testing the callback method out. I’ll let you know.

Seems to be working! Thanks, Irvin.

Not sure why the $.when methodology didn’t work. Seems like it should accomplish the same thing.

Hey Matt,


I agree that $.when would be the ideal pattern. Seems just not implemented yet.


Call it fate or happenstance, but I just happened to have struggled with the same issue hours before your post and followed one of Pat’s replies to another post. What a community!


Best,

Irvin

Nice. I’ve never seen a software support community as effective as this one.

Using deferreds and promises should work.  I’ll have to do a bit of research to see what is going on here.