Skip to main content

I am trying to run a javascript library inside of a skuid component on a lightning page. The javascript is loaded into the page as a static resource. When the component loads on the page it gives me this salesforce error 

“Cannot read property ‘application/pdf’ of undefined]
eval()@https://org.lightning.force.com/resource/1518608135000/pdfobject/PDFObject-master/pdfobject.min.js

When I preview the page it loads correctly and displays how we want it to.

Hi Spencer. 
Check your Javascript code and make sure all your variables are declared explicitly as var

This happens when your JS has any type of variable such:


msg = ‘any Value’;


at running time you will get an error message:

cannot read property msg  of undefined

Correct declaration must be: 

var msg = ‘any Value’;


Hope this helps in any way.
If you prefer, you can share a portion of your JS where you think is raising this error.


Hi Fernando, 
Thanks for responding. I have pasted the little javascript that we have on the page below. As I have said before, the page loads and displays correctly in preview but does not display in a skuid lightning component. I have also attached a picture of the error that we are getting. Thanks again.

$ = skuid.$;


window&#46;setTimeout(function(){<br />&nbsp; &nbsp;&nbsp;<br />var options = {<br />&nbsp; &nbsp; height: "900px",<br />&nbsp; &nbsp; width: "100%" ,<br />&nbsp; &nbsp; pdfOpenParams: { view: 'FitB', page: '1' }<br />&nbsp; &nbsp; };<br />&nbsp; &nbsp;&nbsp;<br />var s3 = skuid&#46;$M('s3file');<br />$&#46;each(s3&#46;data,function(){<br />&nbsp; &nbsp;<br />var s3file = this&#46;URL__c;<br />if (s3file&#46;indexOf("https:&#47;&#47;" == -1)) {<br />&nbsp; &nbsp; s3fileFix = s3file&#46;replace("<a href="http://%22,%22https://%22)" rel="nofollow" target="_blank" title="Link http//https//">http:&#47;&#47;","https:&#47;&#47;")</a>;<br />&nbsp; &nbsp; console&#46;log(s3fileFix);<br />&nbsp; &nbsp; var container = '#my-container' + this&#46;Id;<br />&nbsp; &nbsp; console&#46;log(container);<br />&nbsp; &nbsp; PDFObject&#46;embed(s3fileFix,container, options);<br />}<br />});<br />},500); <img src=".22_AM_inline.png" /> 

Sorry for the late response. 

The error message happens (for some reason) when your Skuid page is running in Lightning Experience. 

But your code is all right, just procure declare this variables as:

                 var s3fileFix = s3file.replace(“http://”,“https://”);


Also, looking at the error message, there is a reference to this PDFObject
If my suggestion doesn’t work, then probably you will need to do something around that utility.



Another problem we run into is making sure you have “generated page support files.”  This is important after you copy a page into a new org (by creating a new page by copying in xml from another page or environment.)  This step pushes your snippets to the SF static resource, making it available to be used by your page.


Fernando and Chandra have shared some great suggestions here. I also wanted to mention that the error message you’re sharing sounds like the snippet could be firing off too soon in Lightning. Whatever the application/pdf property is attached to is apparently undefined when the snippet runs. Any custom code you’re using in Lightning needs to be Lockerservice compliant, so the static resource you’re mentioning may also need to be vetted for compatibility. The fact that the functionality is working in Preview mode but not in Lightning points to the need for strict Javascript, and/or Lockerservice compliance. 


Hi Spencer, I wanted to check in and see if you were able to resolve this. It’s been a while since this thread had any activity, but if you are still having trouble, let us know what your current roadblocks look like and we’ll keep working with you. 

Mark


Reply