Page looping on function in main.js

I’m running the following script. Somewhere in the middle of that, it’s triggering this function in main.js:

And it loops and loops over lines 19531-19534 (doesn’t seem to ever reach 19535).

Here’s my code:

var mA = skuid.$M('Open'),    rA = mA.getFirstRow(),
    $ = skuid.$;
   
//Check for related caller info
$.blockUI({
  message: 'Checking for Caller other than Patient...'
});
console.log('Checking for Caller other than Patient.');
if (rA.Caller\_Other\_Than\_Patient && rA.Caller\_First\_Name\_\_c) {
   console.log('Adding Caller other than Patient as Related Person.');
   var dfd = new $.Deferred(),
        mR = skuid.$M('Related'),
       fullName = rA.Caller\_First\_Name\_\_c + ' ' + rA.Caller\_Last\_Name\_\_c;
   
   //Check if row for caller already exists (if so, update that row)
   var exists = false;
   $.each(mR.data, function(i,row){
       if (row.Name == fullName) {
           exists = true;
           mR.updateRow(row,{
               Relationship\_to\_Patient\_\_c: rA.Relationship\_to\_Patient\_\_c,
               Primary\_Phone\_\_c: rA.Caller\_Primary\_Phone\_\_c,
               Primary\_Phone\_Type\_\_c: rA.Caller\_Primary\_Phone\_Type\_\_c
           });
       }
   });
   
   //If row for caller doesn't exist, create it
   if (!exists){
       mR.createRow({
           additionalConditions:[
               {field: 'Name', value: rA.Caller\_First\_Name\_\_c + ' ' + rA.Caller\_Last\_Name\_\_c},
               {field: 'First\_Name\_\_c', value: rA.Caller\_First\_Name\_\_c},
               {field: 'Last\_Name\_\_c', value: rA.Caller\_Last\_Name\_\_c},
               {field: 'Relationship\_to\_Patient\_\_c', value: rA.Relationship\_to\_Patient\_\_c},
               {field: 'Primary\_Phone\_\_c', value: rA.Caller\_Primary\_Phone\_\_c},
               {field: 'Primary\_Phone\_Type\_\_c', value: rA.Caller\_Primary\_Phone\_Type\_\_c},
           ]
       });
   }
   $.when(mR.save())
        .done(function(){
            console.log('Created Related Person.');
            dfd.resolve();
        })
        .fail(function(){
            console.log('Related Person model save failed.');
            dfd.reject();
        });
    return dfd.promise();    
}

Any thoughts on what might be going on?

main.js is javascript code that Salesforce wrote that comes down with any page that has a Salesforce header on it.  I’m not sure exactly what it’s doing.  Are you getting performance issues because of it?  Or is it just something that came up in a profiler?

The page is hanging up there. It never finishes the snippet that it’s trying to run.

What do your logs look like?  Are you getting the “Checking for caller other than patient” and “Created Related Person” items in your log?

Ok, I realized that my if statement was wack. I’ve updated my code as follows. Now I’m getting the error “object is not a function” on skuid_SkuidJS:

Here’s my console:

The code:

var mA = skuid.$M('Open'),    rA = mA.getFirstRow(),
    $ = skuid.$;
   
//Check for related caller info
$.blockUI({
  message: 'Checking for Caller other than Patient...'
});
if (rA.Primary\_Phone\_Type\_\_c == 'Caller other than patient' && rA.Caller\_First\_Name\_\_c) {
    console.log('Adding Caller other than Patient as Related Person.');
    var dfd = new $.Deferred(),
        mR = skuid.$M('Related'),
        fullName = rA.Caller\_First\_Name\_\_c + ' ' + rA.Caller\_Last\_Name\_\_c;
    
    mR.updateData({
        callback: function(){
               //Check if row for caller already exists (if so, update that row)
               var exists = false;
               $.each(mR.data, function(i,row){
                   if (row.Name == fullName) {
                       exists = true;
                       mR.updateRow(row,{
                           Relationship\_to\_Patient\_\_c: rA.Relationship\_to\_Patient\_\_c,
                           Primary\_Phone\_\_c: rA.Caller\_Primary\_Phone\_\_c,
                           Primary\_Phone\_Type\_\_c: rA.Caller\_Primary\_Phone\_Type\_\_c
                       });
                   }
               });
               
               //If row for caller doesn't exist, create it
               if (!exists){
                   mR.createRow({
                       additionalConditions:[
                           {field: 'Name', value: rA.Caller\_First\_Name\_\_c + ' ' + rA.Caller\_Last\_Name\_\_c},
                           {field: 'First\_Name\_\_c', value: rA.Caller\_First\_Name\_\_c},
                           {field: 'Last\_Name\_\_c', value: rA.Caller\_Last\_Name\_\_c},
                           {field: 'Relationship\_to\_Patient\_\_c', value: rA.Relationship\_to\_Patient\_\_c},
                           {field: 'Primary\_Phone\_\_c', value: rA.Caller\_Primary\_Phone\_\_c},
                           {field: 'Primary\_Phone\_Type\_\_c', value: rA.Caller\_Primary\_Phone\_Type\_\_c},
                       ]
                   });
               }
               $.when(mR.save())
                    .done(function(){
                        console.log('Created Related Person.');
                        dfd.resolve();
                    })
                    .fail(function(){
                        console.log('Related Person model save failed.');
                        dfd.reject();
                    });
        }
    });
return dfd.promise();
}

Unfortunately, the APIs are slightly different for for skuid.model.Model.save() and skuid.model.Model.updateData().  In save you pass in an object that has a callback property, but in updateData, you just pass in a callback function.

Right Way…

updateData(function(){
   // My Stuff
});

vs.

Wrong Way…

updateData({ callback : function(){
   // My Stuff
}});

We should probably allow the “Wrong Way” to work for updateData, but we haven’t done that yet.

Haha, nice. Yeah, consistency on implementation of callbacks would be nice. Same for updateRow() and createRow().

Not that I’m complaining… I should have read the documentation more carefully!

Closing the loop on this. Got it working! Thanks.

Glad to hear!  Thansk for letting us know.