
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 05:37 PM
Hello guys,
In my client script, I'm trying to use a for to check that the fields are not empty. In this way, once one of these fields is empty, it must take an action. But my script is not working. What should I do?
Thanks!
var fields = ['category', 'cmdb_ci', 'assignment_group', 'short_description'];
var arr = [];
for (var i = 0; i < fields.length; i++) {
var getValue = g_form.getValue(fields[i]);
arr = getValue.split(',');
arr.length;
}
if (arr < 3) {
// do something
} else {
// do something
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 06:24 PM
Hello Flavio,
You can try a logic like this:
function onLoad() {
var my_category = g_form.getValue('category').length;
var my_cmdb_ci = g_form.getValue('cmdb_ci').length;
var my_assignment_group = g_form.getValue('assignment_group').length;
var my_short_description = g_form.getValue('short_description').length;
if (my_category == 0 && my_cmdb_ci == 0 && my_assignment_group == 0 && my_short_description == 0) {
g_form.addInfoMessage('Four fields are empty.');
}
}
Please mark my response as Correct or Helpful, if you find it appropriate.
________________________
Carlos Camacho
https://www.linkedin.com/in/camachojunior

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 06:24 PM
Hello Flavio,
You can try a logic like this:
function onLoad() {
var my_category = g_form.getValue('category').length;
var my_cmdb_ci = g_form.getValue('cmdb_ci').length;
var my_assignment_group = g_form.getValue('assignment_group').length;
var my_short_description = g_form.getValue('short_description').length;
if (my_category == 0 && my_cmdb_ci == 0 && my_assignment_group == 0 && my_short_description == 0) {
g_form.addInfoMessage('Four fields are empty.');
}
}
Please mark my response as Correct or Helpful, if you find it appropriate.
________________________
Carlos Camacho
https://www.linkedin.com/in/camachojunior

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 07:02 PM
Thanks, Carlos!