Uncaught model... I think I have async problems?

Matt SonesMatt Sones 💎💎💎
edited June 25, 2020 in Questions
Here's my code.
var model = arguments[0].model,    row = arguments[0].row;
var mA = skuid.$M('AllAppointments');
mA.createRow({additionalConditions:[
        {field: 'Start__c', value: row.Start__c},
        {field: 'End__c', value: row.End__c},
        {field: 'Room__c', value: row.Room__c}
    ]});
    
model.deleteRow(row);
mA.save();
mA.setCondition(mA.getConditionByName('ThisOne'), mA.getFirstRow().Id);
mA.updateData();
I'm getting the error, 'uncaught model' on the AllAppoitments model. It looks like the save doesn't complete before the update is attempted. How do I handle that properly?

Thanks!

Comments

  • Matt SonesMatt Sones 💎💎💎
    edited February 10, 2017
    Perhaps I found the answer... thanks to Pat for undergoing the agony for the rest of us learners.


    Here's my new code:
    var model = arguments[0].model,    row = arguments[0].row, 
        $ = skuid.$;
    var mA = skuid.$M('AllAppointments');
    mA.createRow({additionalConditions:[
            {field: 'Start__c', value: row.Start__c},
            {field: 'End__c', value: row.End__c},
            {field: 'Room__c', value: row.Room__c}
        ]});
        
    model.deleteRow(row);
    mA.save();
    $.when(mA.save())
       .done(function(result){
           if (result.totalsuccess) {
                mA.setCondition(mA.getConditionByName('ThisOne'), mA.getFirstRow().Id);
                mA.updateData();
           } else {
              console.log('something went wrong...');
              console.log(result);
           }
       })
       .fail(function(result){
            console.log('there was a really bad problem, like connecting to the server');
       });
  • Pat VachonPat Vachon 💎💎💎
    edited June 25, 2020
    I typically use this jquery when function. Also, you'd need to do set a deferred promise if there other actions following this in an action framework.
    var model = arguments[0].model,    row = arguments[0].row,      $ = skuid.$; var mA = skuid.$M('AllAppointments'); mA.createRow({additionalConditions:[         {field: 'Start__c', value: row.Start__c},         {field: 'End__c', value: row.End__c},         {field: 'Room__c', value: row.Room__c}     ]}); model.deleteRow(row);  $.when(mA.save())   .done(function(){   mA.setCondition(mA.getConditionByName('ThisOne'), mA.getFirstRow().Id);   mA.updateData();  })  .fail(function(){                  console.log('Something went wrong querying ProposalLineItemForCurrentTask model.');                  dfdTask.reject();   });
  • Matt SonesMatt Sones 💎💎💎
    edited June 25, 2020
    Nice. What does a deferred promise look like?
  • Matt SonesMatt Sones 💎💎💎
    edited December 7, 2016
    I'm looking at this: https://community.skuidify.com/skuid/topics/mixing-actions-and-snippets

    But I'm not quite sure how to implement.
  • Pat VachonPat Vachon 💎💎💎
    edited January 5, 2016
    image
    var model = arguments[0].model,  row = arguments[0].row,      $ = skuid.$,  dfd = new $.Deferred();  var mA = skuid.$M('AllAppointments');  mA.createRow({additionalConditions:[         {field: 'Start__c', value: row.Start__c},         {field: 'End__c', value: row.End__c},         {field: 'Room__c', value: row.Room__c}     ]});  model.deleteRow(row);  $.when(mA.save())   .done(function(){   mA.setCondition(mA.getConditionByName('ThisOne'), mA.getFirstRow().Id);   $when(mA.updateData())    .done(function(){     dfd.resolve();    })    .fail(function(){                 console.log('Something went wrong querying ProposalLineItemForCurrentTask model.');     dfdTask.reject();    });  })  .fail(function(){                  console.log('Something went wrong querying ProposalLineItemForCurrentTask model.');                  dfdTask.reject();   });  return dfd.promise();
  • Matt SonesMatt Sones 💎💎💎
    edited December 7, 2016
    Sweet. Thanks, Pat!
  • Pat VachonPat Vachon 💎💎💎
    edited January 5, 2016
    Quite welcome. Those two things, jquery when and deferred, have taken me a long way in working with javascript for skuid purposes.
  • Matt SonesMatt Sones 💎💎💎
    edited February 10, 2017
    Hmm...

    It seems like the deferred promise isn't keeping the calendar popup from popping up... https://community.skuidify.com/skuid/topics/calendar-popup-showing-before-deferred-promise-resolved
  • edited November 2, 2017
    @skuid employees,


    Can we add this to documentation?

    "You'd need to do set a deferred promise if there are other actions following this in an action framework."
  • edited October 28, 2016
    Thank you Pat. How did you figure this out? 
  • Pat VachonPat Vachon 💎💎💎
    edited October 28, 2016
    I set to learning jquery the hard way. Lots of trial and error. My first post in this thread was the result.
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!