Skip to main content
Nintex Community Menu Bar
Question

Page looping on function in main.js

  • July 9, 2024
  • 8 replies
  • 46 views

Forum|alt.badge.img+18

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?

8 replies

Forum|alt.badge.img+8
  • 649 replies
  • July 9, 2024

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?


Forum|alt.badge.img+18
  • Author
  • 2192 replies
  • July 9, 2024

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


Forum|alt.badge.img+8
  • 649 replies
  • July 9, 2024

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


Forum|alt.badge.img+18
  • Author
  • 2192 replies
  • July 9, 2024

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();
}

Forum|alt.badge.img+8
  • 649 replies
  • July 9, 2024

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.


Forum|alt.badge.img+18
  • Author
  • 2192 replies
  • July 9, 2024

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!


Forum|alt.badge.img+18
  • Author
  • 2192 replies
  • July 9, 2024

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


Forum|alt.badge.img+17
  • Nintex Employee
  • 3766 replies
  • July 9, 2024

Glad to hear!  Thansk for letting us know.