Skip to main content

I have a page that has a custom function that saves then updates a model. However, the updateData() method doesn’t seem to be working. Everything seems to save fine, but the field editor on the page never changes, though when I refresh the page I can see that the changes occurred. I’m not getting errors in the console, either. Here’s the javascript that is running:

var params = argumentsu0],
    chosenRow = params.item.row,
    classesModel = params.model,
    $ = skuid.$, 
    teacherModel = skuid.model.getModel(‘Teacher’); 
    classModel = skuid.model.getModel(‘Class’);

var teacherRow = teacherModel.getFirstRow();

classesModel.updateRow(chosenRow,‘Teacher__c’,teacherModel.getFieldValue(teacherRow,‘Id’));
classesModel.save({callback: function(result){
if (result.totalsuccess) {
classModel.updateData();            // THIS IS WHAT DOESN’T SEEM TO BE WORKING
        } else {
console.log(result.insertResults}0]);
        }
}});

Peter, 
maybe try skuid.Model.updateDate((classModel])
it looks like its a generic function and not one that is called on an instance of a model.

I see that you’re in Berkeley. Any chance you’d like to get together sometime. I’m at ken@8thfold.com/510.384.7321

Thanks


Peter, It looks like your code is correct.  You can call updateData on an instance of a model like that so there should be no problems there.  I would try to debug this by adding a 


console.log('Got Here!'); console.log(classModel); 

inside your if(result.totalsuccess) block.  And check to see if you see ‘Got Here!’ in your console.

Another thing that you might try is that there is a semi-colon after your definition of teacherModel instead of a comma.  This is putting your classModel variable into the global scope instead of the local scope.  Typically this wouldn’t cause issues, but it does open up that variable to being overwritten in other areas.


Thanks Ben. I made the adjustments you suggested. I put those two lines after “classModel.updateData();”, and I do get the info in the console, but the field editor still isn’t refreshing with the new Class model data.


That’s pretty strange.  Your code looks fine to me.  If a regular trigger is updating the other records, then you should have them updated immediately.  Do you know if there are any @future calls being made in the trigger?  If you’re not making any @future calls, can you grant Skuidify LLC login access to your org and send me an email with your org id?

Thanks


Hey Peter looks like you’re updating class model instead of classes model.


Damn, thats a good one. Sharp eyes Moshe. Sometimes it can be so hard to spot those things.


Moshe, that’s by design. There is a list of classes, from which one pick a specific class. That class is then loaded in a separate model.


I might not be understanding your design here, but if you’re not making any changes to the class model why do you expect that it will have any changes to update?


When the teacher changes on on the chosen class in the classes model, that chosen class becomes the the one that (should be) loaded into the class model. i.e., the class model holds the one class that is the teacher’s (latest) class.


In that case I think you have to call updateData() on the classes model first, and then call updateData() on the class model. I could be wrong. 


Ok, I figured it out.  Unfortunately as of yet, Skuid will not automatically update “Field from another Model” type conditions when their source model is updated.  In your example, your “Class” Model depends on a record from the “Teacher” model.  The Teacher model is updated through interaction with the page, and then the Class model is refreshed.  You’ll need to update the conditions on the Class model manually if you want this to work.

You should be able to set both conditions on the Class model to “Filterable default on” and then give them names.  Once you’ve done this, you can use the following code to update the conditions before you try to update the data.


// Get a reference to the condition that sets TeacherId var teacherIdCondition = classModel.getConditionByName('MyTeacherIdCondition'); // Get a reference to the condition that sets LastestClassId var latestClassIdCondition = classModel.getConditionByName('MyLatestClassIdCondition'); // Set your TeacherId condition classModel.setCondition( teacherIdCondition, &nbsp;teacherModel.getFieldValue(teacherRow,'Id') ); // Set your LatestClassId condition classModel.setCondition(<br> latestClassIdCondition, chosenRow.Id ); // Refresh your model now that you have the conditions set classModel.updateData(); 

Let me know if this works for you.


Yup, that works! I forgot about that dependency, sorry. Instead of setting the conditions myself, should I also be able to just update the teacher model, then update the class model? I think I’d have to do the latter in the callback of the former, though, right?


For now, the dependent model and the controlling model must be updated in the same call for the dependency to work correctly.  For instance, you could do this by using the syntax that Ken suggested earlier and putting both models in the array to be updated.

skuid.model.updateData((teacherModel,classModel],function(results){
   // Callback code goes here
});

However, you might run into some issues with your particular instance since you’re kind of combining a create new page and a detail page at the same time.  I think you’ll run into issues with this if your id parameter is not set in your url.  It should work correctly if that id parameter is set from the beginning though.  I forget if you do a page redirect after the new teacher is created or not, but if you do, then you should be fine.