I'm trying to use a for to check if the fields are not empty.

Flavio Tiezzi
Kilo Sage

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
 }
1 ACCEPTED SOLUTION

Carlos Camacho
Mega Sage
Mega Sage

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

View solution in original post

2 REPLIES 2

Carlos Camacho
Mega Sage
Mega Sage

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

Thanks, Carlos!