- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2018 10:30 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 09:06 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 01:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 08:53 AM
Which version of ServiceNow do you have? Maybe the GlideForm API changed a bit. When I try it in Madrid Patch 0, g_form.getValue('internal_name_of_variable_set') returns a string and not an array.
Depending on which version you have it might be good to test for both:
g_form.getValue('internal_name_of_variable_set') == [] || g_form.getValue('internal_name_of_variable_set') == '[]'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2019 12:09 AM
The London version.
Thank you for the information, that is good to know when using later versions than London.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2019 02:23 PM
I ran into this same issue today (Madrid Patch 2). In iFrame, it returns a string. In the service portal, it returns an array. Go figure. Have to check for both of them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2019 11:14 AM
Laurent,
I used this solution on one of our items but it doesn't seem to work on the service portal. Any idea why? Not seeing errors in the console, so not sure what's going on.
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 instead, it looked like this: if (g_form.getValue('internal_name_of_variable_set') == []) - etc etc.
Now it looks at the array and checks if it is empty, and not a string '[]'.