Printing after load

Hello all - interesting dilemma here. We have been using a third party provider to generate many of our PDF documents, and we’re trying to move away from that. We’ve been building our own Skuid pages and using CSS to get the format correct. Now we want to make it so as soon as the page is finished loading, it automatically calls a print function. I’ve been messing around with this for a few days and have been having some issues - sometimes it will work right and sometimes it won’t, but that’s partly because I had been writing my inline code wrong to begin with. This is my code as it is right now:

(function(skuid){<br> var $ = skuid.$; var models = skuid.model.map(); var SingleSerial = models.SingleSerialNumbers; console.log("1"); console.log(skuid.model.load(SingleSerial)); $.when(skuid.model.load(SingleSerial)).then(function(){ console.log("3"); print(); }); })(skuid); 

Basically, we want to give the page time to load the model information before it tries to send the print command. This is the closest I’ve gotten, but I’m pretty sure it’s not loading the model info correctly because the when statement is consistently failing - I can see that in the console, for sure.

I think I’m missing something. I think the model data isn’t loading correctly, so the variable SingleSerial is probably coming up as undefined, which will always lead the when statement to fail. I’m just not sure how to fix that part. Any help would be greatly appreciated.

Made a little progress - realized I could get most of this to happen after the page load, which is why it was undefined earlier. But the option to wait for the model to finish loading is still erroring out.

(function(skuid){ var $ = skuid.$; $(document.body).one('pageload',function(){ var models = skuid.model.map(); var SingleSerial = models.SingleSerialNumbers; console.log("1"); console.log(SingleSerial); $.when(skuid.model.load(SingleSerial)).then(function(){ console.log("3"); print(); }); }); })(skuid);

The console shows this error:

Uncaught (in promise) TypeError: a.getDataSource is not a function

Still messing with it but if anyone has any suggestions, I’m all ears.

Apparently I just fixed it on my own. Instead of trying to call the load for the individual model, I changed it to check for skuid.model.load(models) and it’s working the right way.

Using the pageload function is right.   Have you tried simply running the print function directly - rather than waiting of rhte model.load?  I think the pageload won’t get triggered until after the models are loaded. 

Yes, I have, and it was triggering the print function before the load finished. The code I have now is actually working properly, every reload.

(function(skuid){ var $ = skuid.$; $(document.body).one('pageload',function(){ var models = skuid.model.map(); var SingleSerial = models.SingleSerialNumbers; $.when(skuid.model.load(models)).then(function(){ print(); }); }); })(skuid);
<br>