Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

How to control the number of file attachments

t-takumi
Tera Contributor

I have created a catalog item using Record Producer.
The "Add File" field in the catalog allows multiple files to be attached.

I would like to restrict this so that only a single file can be attached.

Please let me know if there is a standard way to achieve this.
I would also like to know how to implement this control via customization.

ttakumi_0-1787194579706.png

 

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@t-takumi 

you can use onSubmit catalog client script for this

this will work in both Native + Portal

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 > 1) {
                alert('You must add only 1 attachment before submitting this request.');
                return false;
            }
        }
    } catch (ex) {
        // native view
        var length = getSCAttachmentCount();
        if (length == 0) {
            alert('You must add only 1 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 as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

thank you, Ankur Bawiskar .


I understand that the file is checked upon transmission.
Is it possible, then, to perform the check when the file is attached?
 

@t-takumi 

not possible

if you are using the paper clip icon the validation happens on submit

another approach I shared below, better go with that

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Ankur Bawiskar
Tera Patron

@t-takumi 

Another easy way

1) disable attachment on portal using Hide attachment checkbox

AnkurBawiskar_0-1787195877404.png

 

2) create attachment type variable and make it mandatory -> it accepts only 1 file

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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