- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 06:42 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 07:32 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 06:47 AM
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.
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 07:42 AM
Try out one of my code...
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 07:43 AM
I set the isolate is false but still I am facing the issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2019 07:50 AM
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
Abhishek Gardade