How to prevent to submit if Attachment is not attached in a catalog

AaravOjha
Tera Contributor

Please provide script for how to prevent a catalog to submit without attachment using GlideAjax

 

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@AaravOjha 

if you are referring to catalog item then use this and it will work in both native + portal without glideajax

function onSubmit() {
    //Type appropriate comment here, and begin script below
    try {
        var count = getRPAttachmentCount();
        if (window == null) {
            // portal
            if (this.document.getElementsByClassName('get-attachment').length == 0) {
                alert('You must add attachment before submitting this request.');
                return false;
            }
        }
    } catch (ex) {
        // native view
        var length = getSCAttachmentCount();
        if (length == 0) {
            alert('You must add attachment before submitting this request.');
            return false;
        }
    }
}

function getRPAttachmentCount() {
    var length;
    try {
        length = angular.element("#sc_cat_item_producer").scope().attachments.length;
    } catch (e) {
        length = -1;
    }
    return length;
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader