Dinesh Kumar11
Kilo Sage
Kilo Sage

This can be achieved by writing any one of the catalog client scripts as shown below:

 

A) Configure OnSubmit catalog client script as below: 

function onSubmit() {

    var numberofemployees = g_form.getValue('how_many_employees_select_box'); //Read the select box variable

    if (numberofemployees == "7")//Check your variable choice condition as per the requirement
 {
        try {
            var attachments = document.getElementById('header_attachment_list_label');
            if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
                alert(getMessage('You must attach the completed form before submitting this request.'));
                return false;
            }
        } catch (e) { //For HR Service Portal
			var count = getSCAttachmentCount();
            if (count <= 0) {
                getMessage('You must attach the completed form before submitting this request.', function(msg) {
                    alert(msg);
                });
                return false;
            }
        }
    }
}

 

B)  Configure OnSubmit catalog client script as below:

 

function onSubmit() {

    var condition = g_form.getValue('request_related');//Get the value of the catalog variable

    if (condition == 'ABC') // Specify the variable choice value condition
{
        var countRequired = 2; // define the total no.of attachments to be attached before submit 
        if (window == null) {
            // portal
            if (this.document.getElementsByClassName('get-attachment').length != countRequired) {
                alert('You must add attachments before submitting this request.');
                return false;
            }
        } else {
            // native view
            var length = $j("li.attachment_list_items").find("span").length;
            if (length != countRequired) {
                alert('You must add attachments before submitting this request.');
                return false;
            }
        }
    }
}

 

Hope you will find it as helpful. Don’t forget to Mark it Helpful and Bookmark article so you can easily find on your profile.

Thank you,
Dinesh Kumar Raghu,
Capgemini India Pvt Ltd.

GmailID : dineshkumar.raghu9426@gmail.com

Comments
brahmandlapally
Mega Guru

to let you know the best practice is avoiding DOM manipulation techniques.

Slava Savitsky
Giga Sage

Rather than doing a nasty DOM manipulation, it is much better to use a variable of type Attachment, which can be made visible/hidden and mandatory/optional with a simple UI policy. No coding is needed at all.

Max_MS
Tera Contributor

@Slava Savitsky As of now the attachment variable only allows one attachment, which is not ideal sometimes :'(Screenshot 2025-08-22 104006.png

Version history
Last update:
‎11-14-2023 09:29 AM
Updated by:
Contributors