Need to make attachment mandatory in a Catalog Item if a checkbox is checked

Bart Jan Bultma
Kilo Sage

I have a small form in this Catalog item. When one of the checkboxes is ticked, I need the attachment to be mandatory. If it is not checked it must not be mandatory.

I have read a ton of articles on how to do this, all different. Can I use a UI policy to change the OOTB 'Mandatory attachment' variable? That would seem easiest to me.

Most articles seem to work around it with a UI script

1 ACCEPTED SOLUTION

Solved,  condition==true had to be condition=='true'

View solution in original post

7 REPLIES 7

Thank you very much for your entry!! I've been reviewing multiple articles and was going in circles.

I would change the g_form.addErrorMessage to:

g_form.showFieldMsg(<field for the error>, <Message to display>, <type of message>)

Example:

g_form.showFieldMsg('afstemming_met_stakeholder', 'Please attach a file', 'error')

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var checkboxis=g_form.getValue('identify_the_purpose');//PAss correctly
    if(checkboxis=='marriage') //execute if checkbox is true
    {
        try { //Works for native UI/backend
            var attachments = document.getElementById('header_attachment_list_label');
            if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' )
                {
               
                alert("Attachment mandatory");
                return false;//abort submission
            }
           
        }
        catch(e) { //Works for Portal
            if ((this.document.getElementsByClassName('get-attachment').length == 1) || (this.document.getElementsByClassName('get-attachment').length == 0)){
                alert('Attachment mandatory.');
                return false;
            }
        }
    }
}