How to make attachments mandatory in portal for only specific software's in the software table?

Ramya66
Tera Contributor

There are some software's in software table for which if user selects that particular software in portal, then attachment must be mandatory.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can refer my blog which works in native+portal; enhance it as per your requirement

If it helps please mark it helpful and also bookmark it

Verify Mandatory Attachments Count on Catalog Item

Regards
Ankur

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

View solution in original post

8 REPLIES 8

eumak
Tera Guru

Hello Ramya,


Making the attachment mandatory based on the specific selection, It won't be possible without DOM manipulation(Not Recommended). We can achieve by writing an onSbumit() client script for that field. Please find the code below

function onSubmit() {
    if (g_form.getValue("Field_value") == 'valueCheck') { //get the value
        try {
            var attachments = document.getElementById('header_attachment_list_label');
            if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
                alert("Please attach before submitting the request.");

                return false;
            }
        } catch (e) {

            if ((this.document.getElementsByClassName('get-attachment').length == 0)) {
                alert('Please attach before submitting the request.');
                return false;
            }

        }
    }
}

Mark it helpful or correct, If Applicable

Cheers..!
Happy Learning:)
Tushar



 

Mark it as helpful or correct, If Applicable


Cheers..!

Happy Learning:)

Tushar

@Ramya 

Thank you for marking my response as helpful.

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

Cheers..!
Happy Learning:)
Tushar

Mark it as helpful or correct, If Applicable


Cheers..!

Happy Learning:)

Tushar

Hello Ramya,

Happy to know, you got the solution.

Mark my answer correct, If Applicable

Cheers..!
Happy Learning:)
Tushar

Mark it as helpful or correct, If Applicable


Cheers..!

Happy Learning:)

Tushar

Raghu Ram Y
Kilo Sage

Hello @Ramya

Try like below..tested..working...

Note : Make sure to set Isolate script as false

function onSubmit() {
    var getValue = g_form.getValue('software_fieldname');
    if (getValue == 'software name 1' || getValue == 'software name 2') {
        if (this.document.getElementsByClassName('get-attachment').length == 0) {
            g_form.addErrorMessage('Please Attach a file');
            return false;
        }
    }
}