We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Make an attachment mandatory using select box choice.

Roly
Kilo Contributor

Hi

I'm building a form to do with budgets, so there is a requirement that when an option is selected from a select box it is then mandatory to attached a exemption word docx form to the form before it can be submitted.

So if the user chooses "over £1000" I need a text box to appear underneath and then the attachment option which is on all forms needs to be then mandatory.

I can't seem to work out how to do this?  Would a UI policy do it?

Cheers

Roly

11 REPLIES 11

@Roly 

the below script should work fine in both native and portal

Ensure the following

  • Isolate Script is set to false on this onSubmit catalog client script
  • This field is not on form but from list you can set it to false
  • This field is by default true

Script Below:

Ensure you use valid variable name and the choice value here for Over £1000

function onSubmit() {
	//Type appropriate comment here, and begin script below

var value = g_form.getValue('variableName'); // give valid variable name here

// give proper choice value for Over £1000

if(value == 'Over £1000'){

	if(window == null){
		// portal
		if(this.document.getElementsByClassName('get-attachment').length == 0) {
			alert('You must add attachment before submitting this request.');
			return false;
		}
	}
	else{
		// native view
		var length = $j("li.attachment_list_items").find("span").length;
		if(length == 0){
			alert('You must add attachment before submitting this request.');
			return false;
		}
	}
}

}

find_real_file.png

Regards
Ankur

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

Ankur Bawiskar
Tera Patron

@Roly 

Hope you are doing good.

Let me know if that answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

 

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