How to dynamically enforce mandatory attachment on Record Producer based on Multiple Choice variable

Emine
Tera Contributor
Hi everyone,
 
I'm struggling with a requirement on a Record Producer in the Service Portal.
I have a Multiple Choice variable (Values: 'yes', 'no'). If the user selects 'no', the checkbox "Mandatory Attachment" on the record producer tab Portal settings should be set to true.
What I've tried:
1. Catalog Client Script (onChange)
2. UI Policy
But they didn't work, Can you help me?
1 REPLY 1

Ankur Bawiskar
Tera Patron

@Emine 

that's not going to work

you need onSubmit catalog client script which checks the value is No then make attachment mandatory on portal

Ensure Isolate Script Field = False

This field is not on form but from list you can set it false

function onSubmit() {

    if (g_form.getValue('variableName') == 'no' && this.document.getElementsByClassName('get-attachment').length == 0) {
        g_form.addErrorMessage('You must add attachment before submitting this request.');
        return false;
    }
}

💡 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