Make Multi-row variable set mandatory and limit number of entries

Eash1
Tera Expert

Hello Experts,

I am using Multi row variable set in my catalog item and it works perfect but i am stuck on below 2 requirements.

Does anyone have any insights to it ?

 

  • How to make sure at-least one entry is selected as part of Multi row variable set. I tried to do a on-submit and later read through docs that it is not supported
  • How to limit number of entries ? like just 10

Thank you,

Easwar

1 ACCEPTED SOLUTION

LaurentChicoine
Tera Guru

Hi Easwar,

I was looking to make a sure at least one entry exist in the multi row variable set. I don't know if you found a way to it.

I came with the solution of a on submit client script (I think what the doc refers to is for on submit that would run after each entry being added). Here is a code snippet that I was able to use to make sure there is at least one row:

function onSubmit() {
	if(g_form.getValue('internal_name_of_variable_set') == '[]'){
		g_form.addErrorMessage('You must enter at least 1');
		return false;
	}
}

g_form.getValue returns a JSON of the variable set, so simply by checking if it is an empty array, I was able to block submission in that case.

 

I think you could solve your second requirement with this (parsing the JSON and doing a length validation: array.length < 11). However this is not the best User experience as you are checking this on submit while the user already entered more than 10 entries.

View solution in original post

25 REPLIES 25

Jesper Hildebra
Kilo Expert

Hi Laurent

I just used your solution and it (almost) worked.

It did not allow me to submit, even though there were no values inserted. Then I talked to a colleague and we removed the ' ', from around the brackets [].

So it instead, it looked like this: if (g_form.getValue('internal_name_of_variable_set') == []) - etc etc.

Now it looks at the array, and not a string '[]'.

It worked for me thanks

LaurentChicoine
Tera Guru

For your information, there is a new variable attribute in the New York release that meets your requirement for a maximum number of rows: https://docs.servicenow.com/bundle/newyork-it-service-management/page/product/service-catalog-manage...

For your example of maxium 10 rows, simply add max_rows=10 in the variable attributes.

monika223115
Kilo Contributor

Hi Guys, We are currently in Madrid. I tried this solution. I created a On Submit Catalog Client Script. The Script is not working. Any ideas here. I need the user to enter at least one row. 

Lieve Verhelst
Tera Expert

Thanks @Laurent Chicoine 

This helped me a lot!

Certainly the portal part :

g_form.getValue('internal_name_of_variable_set') == ''