need client script for attachment validation for check box in catalog item

ravichanduk
Mega Expert

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;

}

}

   

}

3 REPLIES 3

Chuck Tomasi
Tera Patron

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.



TechNow Episode List



Docs: Client Scripts


Docs: GlideForm


Docs: GlideAjax  


Developer: Client Scripting Technical Best Practices Overview


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!

Chandu Telu
Tera Guru
Tera Guru