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

palanikumar
Mega Sage

Hi,

You cant use "Mandatory attachment" field or UI Policy. "Mandatory attachment" field make the attachment mandatory for the catalog item. You can't apply using condition. You have to use client script. Refer below thread:

 https://community.servicenow.com/community?id=community_question&sys_id=47dc4b0cdbff90509e691ea66896...

Thank you,
Palani

I'm going to try that one out, thanks for the clear answer about UI policy!

Bart Jan Bultma
Kilo Sage

I created a Catalog Client Script, added it to the catalog item that I want it to run on, with the following code. What am I missing? I dont get the error message at all.

The variable 'afstemming_met_stakeholders' is a checkbox in the form. the UI type is set to Mobile/Service Portal. Type is onSubmit and applies on Catalog Item view.

function onSubmit() {
    //Type appropriate comment here, and begin script below
	var condition= g_form.getValue('afstemming_met_stakeholders');
	
	if(condition==true)
	{
		if (this.document.getElementsByClassName('get-attachment').length == 0)	
		{
			g_form.addErrorMessage('Please Attach a file');
			return false;
		}
	}
}

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