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

AbhishekGardade
Giga Sage

hey Chaitanya,
Check out my article for this solution:

Possible Ways for Making an Attachment Mandatory : Service Portal/Native UI

NOTE:

Well with the introduction of London came a new field called 'isolate script'. New client-scripts are run in strict mode, with direct DOM access disabled. Access to jQuery, prototype and the window object are likewise disabled. To disable this on a per-script basis, configure this form and add the "Isolate script" field. To disable this feature for all new globally-scoped client-side scripts set the system property "glide.script.block.client.globals" to false.

Before running this script, Make an Isolate script: False on client script / catalog client script.

find_real_file.png

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

Try out one of my code...

Thank you,
Abhishek Gardade

I set the isolate is false but still I am facing the issue

Remove your all code and  Try with this client script:

function onSubmit() {
if(this.document.getElementsByClassName('get-attachment').length == 0) {
           alert(''You must add an attachment before submitting this request.');
           return false;
           }
}

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

 

Thank you,
Abhishek Gardade