In on submit client script I am getting error message in portal : "TypeError: Cannot read property 'getElementById' of null"

k chaitanya kum
Giga Contributor

Hi Folks,

I have one client script in on submit this will check the attachments are added or not, but if attachments are added also this is not working any help this is the script:

 

function onSubmit() {

if(g_form.getValue(field) == 'true' ) {


var MSG_NO_ATTACHMENT = "Please add aattachemnts";


try { 



var attachmentsNon = document.getElementById('header_attachment_list_label'); 
alert(attachmentsNon);
if (attachmentsNon.style.visibility == 'hidden' || attachmentsNon.style.display == 'none' ) {
alert(MSG_NO_ATTACHMENT);
return false;
}
} catch(e) { 
alert(e);
var count_att = getSCAttachmentCount();
alert(count_att);

if(count_att <= 0) {
alert(MSG_NO_ATTACHMENT);
return false;
}
}
}
}

I am getting error : TypeError: Cannot read property 'getElementById' of null and it is not allowing submitting the request in portal I added attachments 

Any help?

Regards,

Chaitanya Kumar. 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Chaitanya,

set isolate = false for that onSubmit client script and try once

https://community.servicenow.com/community?id=community_blog&sys_id=c5c46364dbba6b007d3e02d5ca9619cb

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Michael Fry1
Kilo Patron

Do you have Isolate script set to false? This is a field on the client script form.

YES BUT STILL NOT WORKING

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Chaitanya,

set isolate = false for that onSubmit client script and try once

https://community.servicenow.com/community?id=community_blog&sys_id=c5c46364dbba6b007d3e02d5ca9619cb

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

YES BUT STILL NOT WORKING 

Nen
Tera Guru

Hi! Have you added the properties to enable the DOM manipulation?

glide.script.block.client.globals

https://community.servicenow.com/community?id=community_question&sys_id=d3e10fa9db98dbc01dcaf3231f96...