TypeError: Cannot read properties of null (reading 'document'): function () { [native code] }

Renu9
Tera Contributor

Hi All,

I am using an onsubmit client script like below, which is throwing the below error in native UI when I am making any updates to the record.

Please help me here what is wrong

TypeError: Cannot read properties of null (reading 'document'):
function () { [native code] }

 

function onSubmit() {
    //portal
    var countRequired = 2;
    if (window == null) {
        if (this.document.getElementsByClassName('get-attachment').length != 2) {
            g_form.addErrorMessage("Please add at least one attachment.");
            return false;
        }
    }
    //native
    else {
        var count = getCurrentAttachmentNumber(); // this function is out of the box
        if (count != 2) {
            g_form.addErrorMessage('You must add an attachment');
            return false;
        }
    }
}
3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

It seems like the error is caused by the this.document... line, even though it shouldn't be running that in the native UI due to the window == null condition.  Confirm that Isolate script is unchecked, and the UI Type = All. An alternate method of identifying when portal is being used is

if (typeof parent.angular != 'undefined') { // portal

Hi @Brad Bowman  

yes isolate script is unchecked and ui type is set to all already 

now i have added the alternate method of identifying portal but still it is throwing the same error in native view

 

If you comment only the if line containing this.document, and the closing } does it run without error?  If so, do you get the text of the portal or native ErrorMessage - or both?