
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2016 11:03 AM
I have a Variable Set with 6 variables. Each single line text.
I have a simple Catalog Client Script thats supposed to be applied to the variable set, which checks if the values put in the fields are, 1) numbers and, 2) from (0 - 30).
But, I only know how to make it check ONE variable, so I'd have to create this script for the other 5 variables to get it to work properly for each. I don't want to do this.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideErrorBox('tlos_place1');
var partNumber = g_form.getValue('tlos_place1');
var numbervalid = /^([0-9]{1,2})$/;
if (!(partNumber.match(numbervalid)) || partNumber > 30) {
g_form.showErrorBox('tlos_place1','That entry isn\'t in the expected range \(0-30\). Please try again.',false);
return;
} else {
g_form.hideErrorBox('tlos_place1');
return;
}
}
How do I get it to work for all the variables in the variable set w/o attaching the script to each individual variable manually?
Solved! Go to Solution.
- Labels:
-
Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2016 01:04 PM
OK,
Since I had to attach a onChange client script to each variable in the set anyway, I just went with:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var num = isNaN(newValue);
if (num || newValue > 30) {
g_form.showFieldMsg('place1','That entry isn\'t in the expected range \(0-30\). Please try again.','error');
} else {
g_form.hideFieldMsg('place1', true);
}
}
I think I might have had to create a global onLoad script for the Catalog Item in order to get it working the other way. Unfortunately, I don't have access to do that yet.
So rlatorre pretty much had my answer this time.
Thank you all!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2016 12:15 PM
I guess I should have said that. This is Helsinki and the Service Portal.
Sorry to be so dense, but you're saying that I have to go anonymous function time on the onLoad?
var checkThisValue = function() {
function checkParticipants(someVar) {
// g_form.hideErrorBox(someVar);
var partNumber = g_form.getValue(someVar);
var numberValid = /^([0-9]{1,2})$/;
if (!(partNumber.match(numberValid)) || partNumber > 30) {
g_form.showErrorBox('someVar','That entry isn\'t in the expected range \(0-30\). Please try again.',false);
return;
} else {
g_form.hideErrorBox('someVar');
return;
}
}
}
Or the onChange?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2016 12:24 PM
In the onLoad define it like this
- checkParticipants = function(someVar) {
- // g_form.hideErrorBox(someVar);
- var partNumber = g_form.getValue(someVar);
- var numberValid = /^([0-9]{1,2})$/;
- if (!(partNumber.match(numberValid)) || partNumber > 30) {
- g_form.showErrorBox('someVar','That entry isn\'t in the expected range \(0-30\). Please try again.',false);
- return;
- } else {
- g_form.hideErrorBox('someVar');
- return;
- }
- }
Nothing special to do in the onChange
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2016 12:30 PM
Note that in line 7 and 10 you reference someVar as a string 'someVar' instead

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2016 01:46 PM
Yes!
For whatever reason, your answer is NOW working in my environment too. Without access to the global UI.
So I have my choice of either now.
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2016 01:04 PM
OK,
Since I had to attach a onChange client script to each variable in the set anyway, I just went with:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var num = isNaN(newValue);
if (num || newValue > 30) {
g_form.showFieldMsg('place1','That entry isn\'t in the expected range \(0-30\). Please try again.','error');
} else {
g_form.hideFieldMsg('place1', true);
}
}
I think I might have had to create a global onLoad script for the Catalog Item in order to get it working the other way. Unfortunately, I don't have access to do that yet.
So rlatorre pretty much had my answer this time.
Thank you all!