3

Since a couple of weeks, some of my users have a problem with a custom Javascript button in Classic. They get the error message "Unable to set property 'innerHTML' of undefined or null reference". No line number is reported.

The error does not always occur, and after trying two or three times the button does what it is supposed to do, no error message. The used browser is Chrome. I cannot reproduce this message, I clicked dozens of times and for me, the button always works.

This is the code:

{
    !REQUIRESCRIPT("/soap/ajax/37.0/connection.js")
}
{
    !REQUIRESCRIPT("/soap/ajax/37.0/apex.js")
}
var pdfOverlay = QuotePDFPreview.quotePDFObjs['quotePDFOverlay'];
try {
    var verkoopGroep = "{!Quote.Account_verkoopgroep__c}";
    if (verkoopGroep.indexOf("F0") == 0) {
        pdfOverlay.summlid = '0EH580000003OAC';
    } else {
        var taal = "{!Quote.Account_taal__c}";
        switch (taal) {
            case 'Nederlands':
                pdfOverlay.summlid = '0EH58000000GcPS';
                break;
            case 'Engels':
                pdfOverlay.summlid = '0EH58000000GjHG';
                break;
            case 'Duits':
                pdfOverlay.summlid = '0EH58000000Gg9F';
                break;
            case 'Spaans':
                pdfOverlay.summlid = '0EH5800000085ZN';
                break;
            case 'Roemeens':
                pdfOverlay.summlid = '0EH5800000085ZS';
                break;
            case 'Frans':
                pdfOverlay.summlid = '0EH5800000085ZX';
                break;
            case 'Pools':
                pdfOverlay.summlid = '0EH5800000085Zh';
                break;
            case 'Italiaans':
                pdfOverlay.summlid = '0EH5800000085Zc';
                break;
            default:
                pdfOverlay.summlid = '0EH58000000GjHG';
                break;
        }
    }
} catch (e) {
    alert('Er is een fout opgetreden: ' + e);
    pdfOverlay.summlid = '0EH58000000GcPS';
}
;
pdfOverlay.dialog.buttonContents = '<input value=\"{!$Label.Opslaan_naar_offerte}\" class=\"btn\" name=\"save\" onclick=\"QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').savePDF(\'0\',\'0\');\" title=\"Opslaan naar offerte\" type=\"button\" /><input value=\"{!$Label.Offerte_opslaan_en_per_e_mail_verzenden}\" class=\"btn\" name=\"saveAndEmail\" onclick=\"QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').savePDF(\'1\');\" title=\"Offerte opslaan en per e-mail verzenden\" type=\"button\" /><input value=\"{!$Label.Annuleren}\" class=\"btn\" name=\"cancel\" onclick=\"QuotePDFPreview.getQuotePDFObject(\'quotePDFOverlay\').close();\" title=\"Annuleren\" type=\"button\" />';
pdfOverlay.setSavable(true);
pdfOverlay.setContents('/quote/quoteTemplateDataViewer.apexp?id={!Quote.Id}', '/quote/quoteTemplateHeaderData.apexp?id={!Quote.Id}');
pdfOverlay.display();

It creates a PDF for a quote and displays it. This code has worked properly for the past 3 years, but all of a sudden some of my users have problems with it.

Note that 'innerHTML' does not occur in the Javascript, so the problem occurs in the QuotePDFPreview library? As I use a fixed version of this library, that should rule out any changes on that part. Could some change in Chrome cause this behavior?

  • did you try to have an idea about installed extensions those users have? it could be an extension trying to do something weird. – Bechir Nov 6 at 8:42
  • That is an idea. The three users are using Chrome within Citrix, which limits what they can do with it. But I could check to see if it is possible to install extensions. – Sander de Jong Nov 6 at 8:54
  • I checked the extensions section in the Chrome browser within Citrix and it says something like "Your browser is being managed by your organization". That still doesn't tell me whether users have been able to install extensions or not, though... – Sander de Jong Nov 6 at 9:06
  • do you get the same error when Chrome is in Incognito mode too?(Incognito will disable most of the extensions) – Bechir Nov 6 at 9:08
  • The problem is the unpredictability of the error. You can click this button 10 times and 10 times there is no problem whatsoever. And then suddenly... boom. – Sander de Jong Nov 6 at 9:37
0

It is indeed a timing problem. I changed

pdfOverlay.display();

into

setTimeout(function(){pdfOverlay.display();}, 200);

and now my users do not have this problem anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.