- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2025 07:48 AM
Greetings all,
Is there an easy way to iterate through the list of Variables within a Variable Set and check if any are empty? Say I have a Variable Set with 10 Variables. I'm looking for a way to iterate through all the Variables within the Variable Set, check if they are empty, and if so, possibly display a field message alert. I also only want to capture the Variables within the Variable Set and NOT any of the other Variables outside of the Variable Set (i.e incident.variables.variable_set rather than incident.variables).
Is there an easier way rather than using if (g_form.getValue('variable1') == '' || g_form.getValue('variable1') == null) || .....?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2025 10:22 AM
Hello @lpruit2 ,
Typically you would make the variables mandatory so that the system takes care of checking if they are empty and showing alerts when they are.
But if you need to check this through a script you can do something like this:
var vars = [
'NAME OF VARIABLE 1',
'NAME OF VARIABLE 2',
'NAME OF VARIABLE 3',
'etc'
];
var emptyVars = vars.filter(v => !g_form.getValue(v));
emptyVars.forEach(v => g_form.showErrorBox(v, 'Variable is empty'));
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2025 10:22 AM
Hello @lpruit2 ,
Typically you would make the variables mandatory so that the system takes care of checking if they are empty and showing alerts when they are.
But if you need to check this through a script you can do something like this:
var vars = [
'NAME OF VARIABLE 1',
'NAME OF VARIABLE 2',
'NAME OF VARIABLE 3',
'etc'
];
var emptyVars = vars.filter(v => !g_form.getValue(v));
emptyVars.forEach(v => g_form.showErrorBox(v, 'Variable is empty'));
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2025 12:09 PM
Thanks for the reply, Robert. Further backstory is that some of the Variables within the Variable set are String and some are Select Box. The Select Box's Options are being populated through another script that is pulling data from the table. This population overrides the --None-- option so hopefully this solution will be able to check.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2025 01:25 PM
Hello @lpruit2 ,
The solution identifies all variables where the value is an empty string, which is also the case for select boxes that show "-- None --".
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2025 11:31 AM
Thank you for the solution, Robert. This worked. I'll need to think some more on how I'm filtering the array but it's a great solution.