Restricting the no of entries in a list type field

jkn1
Tera Contributor

Hi All,

I have a short description field type list  which consists of 20 choices/ values

I should allow/restrict users to enter/select any 5 value/choices in short description field 

1 ACCEPTED SOLUTION

Hi,

something like this in onChange of that field

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading) {
		return;
	}

	if (newValue.toString().split(',').length > 5) {
		alert('Please select only 5 values');
	} 
}

OR

you can also use onSubmit

function onSubmit(){

	if (g_form.getValue('fieldName').toString().split(',').length > 5) {
		alert('Please select only 5 values');
		return false;
	} 
}

Regards
Ankur

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

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Please delete this duplicate question

You already asked it 2hrs ago and I responded to it

https://community.servicenow.com/community?id=community_question&sys_id=777b08c0db86195021b59b3c8a96...

Regards
Ankur

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

Hi Sorry again by mistakly I deleted the above thread instead of deleting duplicate thread Plz can u share on change script once agin

Hi,

something like this in onChange of that field

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading) {
		return;
	}

	if (newValue.toString().split(',').length > 5) {
		alert('Please select only 5 values');
	} 
}

OR

you can also use onSubmit

function onSubmit(){

	if (g_form.getValue('fieldName').toString().split(',').length > 5) {
		alert('Please select only 5 values');
		return false;
	} 
}

Regards
Ankur

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

Thank you so much