
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2016 05:34 AM
We have a request page where a user can request updates to the CMDB. Since there is no real way to determine what variables should be mandatory is there a way write a onsubmit client script to loop thought the variables to verify at least one other field was filled out.?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2016 06:01 AM
The easiest thing to do would be to create an array in your client script of all the variable names, then loop through each of the names checking the value of the variable. If none have values return false.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2016 06:01 AM
The easiest thing to do would be to create an array in your client script of all the variable names, then loop through each of the names checking the value of the variable. If none have values return false.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2016 06:07 AM
How would I create an array of all the variable name? Is there a way to do this dynamically so if we add more variables I do not have to update the script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2016 06:15 AM
Hi Brian,
I don't think there's a great way to 'detect' the variables on the item so an array of names would be easiest. What you could do would be to use glideajax and query the variables associated with that item from the server and get all the names back in an array. That gets a little more complex if you have some in and out of variable sets, but it's doable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2016 07:16 AM
Here is the script I created to make this work if anybody else runs into this issue.
function onSubmit() {
//Type appropriate comment here, and begin script below
var reqtype = g_form.getValue('request_type');
var variableName = [];
var variableName = 'variable1,variable2,variable3';
var variable = variableName.split(',');
var length = variable.length;
var a = 0;
for (var i = 0; i<length;i++){
var currentVariable = variable[i];
var checkVariable = g_form.getValue(currentVariable);
if (checkVariable != ''){
a++;
}
}
if (a < 1){
alert('You must tell us what you want to update in the system you selected');
return false;
}
}