Skip to main content

Here’s part of some code for a custom table view:


.attr('href', '/support/servlet/servlet.FileDownload?file=' +&nbsp; (row.Support_User__r &amp;&amp; row.Support_User__r.Photo__r) ?&nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp;row.Support_User__r.Photo__r.skuid__AttachmentId__c :&nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp;null<br>)


I’m getting a javascript error on row.Support_User__r.Photo__r.skuid__AttachmentID__c:


Uncaught TypeError: Cannot read property 'skuid__AttachmentId__c' of undefined


How could the code get past the IF ? when Photo__r is undefined?

Any idea what might be going on here?

That’s because of precedence of the operators.

? is considered more important than +

Your statement 


'/support/servlet/servlet.FileDownload?file=' +&nbsp; (row.Support_User__r &amp;&amp; row.Support_User__r.Photo__r) &nbsp;?&nbsp; row.Support_User__r.Photo__r.skuid__AttachmentId__c : &nbsp;null


is interpreted as


('/support/servlet/servlet.FileDownload?file=' +&nbsp;(row.Support_User__r &amp;&amp; row.Support_User__r.Photo__r)) &nbsp;?&nbsp; (row.Support_User__r.Photo__r.skuid__AttachmentId__c) : (null)


 try putting the whole inline-if into brackets like


&nbsp;'/support/servlet/servlet.FileDownload?file=' + ((row.Support_User__r &amp;&amp; row.Support_User__r.Photo__r) &nbsp;?&nbsp; row.Support_User__r.Photo__r.skuid__AttachmentId__c : &nbsp;null)

Thanks, Thimo!


Reply