
- 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 11:13 AM
Hi
You will have to create an onChange script for each variable, to have a trigger.
But you can create an onLoad script and define the common function to be shared to all of the onChange scripts.
Just define a function outside the default onLoad and it will be available for all other scripts running on that catalog item.
You can then pass the necessary parameters to the shared function, so it knows which field has been changed,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2016 11:27 AM
We do a similar thing and do use onChange Client Scripts for each variable to tell the submitter as they are completing the request that they entered incorrect values.
I think you could also use a onSubmit Client Script to do checks on all the variables and abort if needed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2016 11:42 AM
So, creating an onLoad like so:
function onLoad() {
//Type appropriate comment here, and begin script below
}
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;
}
}
Then an onChange for each variable in the variable set, should do the trick?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
checkParticipants('place1');
return;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2016 11:45 AM
Yes, exactly like that...
Then you only have to maintain your validation logic one place.
If you every migrate to Service Portal, you must declare the shared function with reverse syntax:
xxx = function() {
}