Attachment to be attached if the user Checks the checkbox

Balaraju K B
Tera Expert

Hi Team,

I have a check box in my catalog item

  • If the user checks that check box then he must attach an attachment
  • If the user not checking that check box in this case he can submit the catalog item without attaching.

Please let me know how to get this done?

@Ankur Bawiskar 

 

Thanks in Advance.,

Balaraju K B

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Balaraju K B 

this onSubmit client script should help

1) Ensure the Isolate Script field is set to false for this client script

2) By default when you create new client script it is true

Note:

Ensure you give valid checkbox variable name and your message for alert/form message

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

	if(g_form.getValue('checkbox_variable').toString() == 'true'){
		if(window == null){
			// portal
			if(this.document.getElementsByClassName('get-attachment').length == 0) {
				g_form.addErrorMessage('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){
				g_form.addErrorMessage('You must add attachment before submitting this request.');
				return false;
			}
		}
	}
}

find_real_file.png

Regards
Ankur

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

View solution in original post

15 REPLIES 15

Hi @Ankur Bawiskar 

 

I tried this above script but getting Error as shown in the below image

Please let me know what's the issue and i made isolate script as false as well

find_real_file.png

 

Hi,

Did you set Isolate script field is set to false

please share your script and client script screenshot

Regards
Ankur

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

Hi @Ankur Bawiskar 

Please take a look at my script

find_real_file.pngfind_real_file.png

Hi,

please make Isolate Script as false and then test once

I could see it is set to True

Regards
Ankur

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

No @Ankur Bawiskar 

I made it to false and tested it is giving same error only