getSCAttachmentCount(); function is not working

Pavan S
Tera Contributor

Hi,

 

We have an 'on submit' client script for making the attachment mandatory in portal. 

Even after adding attachment also, the alert is showing like 'Please attach attachements'.

Can anyone help me?

 

We have used the below script 

 

function onSubmit() {

 try {
        var a=g_form.getValue('field_name');
    if (a == "true")
    {

var attachments = document.getElementById('header_attachment_list_label');

if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {

alert('Please attach attachements');

return false;

}

} catch(e) { 

var count = getSCAttachmentCount();

if(count <= 0) {

alert('Please attach attachements');

return false;

}

}
}

8 REPLIES 8

dgarad
Giga Sage

Hi @Pavan S 

Refer below link

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0743672

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Pavan S
Tera Contributor

Hi Dgarad,

 

We have made the changes as per the KB mentioned only. Still it is not working.

 var attachments = document.getElementById('header_attachment_list_label'); 

replace below code check

var attachments = g_form.getControl('header_attachment_list_label');

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Anubhav24
Mega Sage
Mega Sage

Hi @Pavan S ,

I see usage of DOM manipulation, for this you need to check "Isolate Script" to true is that checked in your script.

Please mark helpful/correct if my response helped you.