need client script for attachment validation for check box in catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2018 05:17 AM
Hi i need client script if i am select checkbox yes then attachment validation should be triggered if not it wont trigerred
i tried with below script but if i uncheck the checkbox also it getting validation
function onSubmit() {
try { //Works in non-portal ui
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('You must attach a file to submit');
return false;
}
}
catch(e) { //For Service Portal
if ((this.document.getElementsByClassName('get-attachment').length == 0)) {
alert('You must attach a file to submit.');
return false;
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2018 05:24 AM
My first note on this is - don't do DOM manipulation from a client script. It's the number 1 cause of upgrade issues. If you reference anything from a client script as document.something, you're doing it wrong.
Second note, use a GlideAjax call to query the server and check if the sys_attachment table has one or more records with the table_name and table_sys_id corresponding to the record you want to check against. You can use a GlideAggregate query to count those records VERY fast.
See TechNow episodes 5, 6, and 33 for more information on client scripts, GlideAjax, and script includes.
Docs: Client Scripts
Docs: GlideForm
Docs: GlideAjax
Developer: Client Scripting Technical Best Practices Overview
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 08:33 AM
Hey Chuck,
I've been trying to do a client validation if a user has an attachment. The thing is that I need to do it on submit, and I'm working on a scoped app. The only way I found how to do it, is on the server side (business rule). Is there something I'm missing? I don't have sync GlideAjax, I don't have DOM manipulation, and I'm working on the itil view, so the SP tools are not helping. Anything I might be missing?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2018 05:30 AM
HI Ravi,
Cehck the below link it may help you
Require attachment for catalog item in Service Portal
How to validate file attachment in onSubmit Catalog Item?