Skip to main content
Inspiring
November 18, 2018
Question

if loop with many parameters (&& * 500)

  • November 18, 2018
  • 4 replies
  • 802 views

i have a if loop to check some parameters :

var A0 = this.getField("Dropdown14.0").value

var A1 = this.getField("Dropdown14.1").value

var A2 = this.getField("Dropdown14.2").value

var A3 = this.getField("Dropdown14.3").value

var A4 = this.getField("Dropdown14.4").value

.

.

.

var A500 = this.getField("Dropdown14.500").value

if (num1!=0 && A0=="check" && A1!="check" && A2!="check"... A500!="check")

now the problem is A0 go to A500.....

the only solution is to write A0=="check" && A1!="check" && A2!="check"....

any smarter solution?

This topic has been closed for replies.

4 replies

hackertomAuthor
Inspiring
November 19, 2018

try67​ i try to understand your code and change something commands but when i have 2 dropdown check how to add text on correct field?

var b = (num1!=0 && A0=="check");

    var b1= (num1==0 && A0=="check");

if (b==true) { 

    for (var j=this.getField("Text68").value; j<=52; j++) { 

         var fz = this.getField("Dropdown14."+j); 

         if (fz.valueAsString=="check") {

         this.getField("Text1").value=this.getField("Text1").value=J1+", check ("+num1+")"+" "+al+" with info :"

             b=false; 

             break; 

         } 

    } 

}

if (b1==true) { 

    for (var j=1; j<1; j++)  {

         var fz = this.getField("Dropdown14."+j); 

         if (fz.valueAsString=="check") {

         this.getField("Text1").value=this.getField("Text1").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"            

            b1=false; 

             break; 

         } 

    } 

}

hackertomAuthor
Inspiring
November 19, 2018

e.g.

i write a regular expression on text2 field if this is true then check if dropdown14.0 has check value and past to text1 the results

deferent if num1!=0 or num1=0

e.g.2

if i write on text3 filed system check if dropdown14.0 if dropdown14.1 has "check" value and put on text1 for drop down14.0 check or text2 for dropdown14.1 check. if dropdown14.0 if dropdown14.1 has same check value then put text to biggest (dropdown 14.1 => text2)

e.g.3

if regular expression on text4 is true

then

check dropdown list if check value and put right text results

14.0 >> check?

14.1 >>check?

14.2 >>check?

if

14.0 !=check

14.1 ==check

14.2 ==check

then put result on text3

e.g.4

if regular expression on text6 is true

then

check dropdown list if check value and put right text results

14.0 >> check?

14.1 >>check?

14.2 >>check?

14.3 >>check?

14.4 >>check?

14.5 >>check?

if

14.0 ==check

14.1 !=check

14.2 !=check

14.3 !=check

14.4 !=check

14.5 !=check

then put result on text1

Bernd Alheit
Community Expert
Community Expert
November 19, 2018

You can use something like this:

var fld_name = "";

if (A18!="         check") {

  if (A17!="         check") {

  ...

 

  } else {

    fld_name = "Text19";

  }

} else {

  fld_name = "Text19";

}

if (fld_name != "") {

  if (num != 0) this.getField(fld_name).value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"; 

  else this.getField(fld_name).value=J1+", check ("+num1+")"+" "+al+" with info :";

}

hackertomAuthor
Inspiring
November 18, 2018

thanks for this answers team...

Karl heinz Kremer how to check between values in arrays?

var A=["Dropdown14.0","Dropdown14.1"....,"Dropdown14.500"];

this e.g. work?:

if (num1!=0 && this.getField(fields[0]).value=="check" && this.getField(fields[1,10]).value!="check")

i want to check Dropdown14.1.Dropdown14.2,...Dropdown14.10    != check   ??

Inspiring
November 18, 2018

Once the values are in an array, one can remove the values that equal "check" by applying a filter to the array. Then one can process the new/revised array of values.

var A =[];

for (var i=0; i<500; i++) {

    A = this.getField(“Dropdown.14.” + i).value;

}

function NotCheck(element){

// remove elements not equal to check;

return element != "check";

}

A = A.filter(NotCheck); // apply filter to array;

hackertomAuthor
Inspiring
November 19, 2018

var A0 = this.getField("Dropdown14.0").value

var A1 = this.getField("Dropdown14.1").value

var A2 = this.getField("Dropdown14.2").value

var A3 = this.getField("Dropdown14.3").value

.

.

.

var A52 = this.getField("Dropdown14.52").value

var J1 = this.getField("Text58").value 

var num = 0;

var num1 = 0;

var al = user;

var als = users;

.

.

.

if (num!=0 && A0=="         check" && A1!="         check" && A2!="         check" && A3!="         check" && A4!="         check" && A5!="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text1").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A0=="         check" && A1!="         check" && A2!="         check" && A3!="         check" && A4!="         check" && A5!="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text1").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A1=="         check" && A2!="         check" && A3!="         check" && A4!="         check" && A5!="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text2").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A1=="         check" && A2!="         check" && A3!="         check" && A4!="         check" && A5!="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text2").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A2=="         check" && A3!="         check" && A4!="         check" && A5!="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text3").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A2=="         check" && A3!="         check" && A4!="         check" && A5!="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text3").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A3=="         check" && A4!="         check" && A5!="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text4").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A3=="         check" && A4!="         check" && A5!="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text4").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A4=="         check" && A5!="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check"&& A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text5").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A4=="         check" && A5!="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text5").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A5=="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text6").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A5=="         check" && A6!="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text6").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A6=="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text7").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A6=="         check" && A7!="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text7").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A7=="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text8").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A7=="         check" && A8!="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text8").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A8=="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text9").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A8=="         check" && A9!="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text9").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A9=="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text10").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A9=="         check" && A10!="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text10").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A10=="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text11").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A10=="         check" && A11!="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text11").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A11=="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text12").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A11=="         check" && A12!="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text12").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A12=="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text13").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A12=="         check" && A13!="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text13").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A13=="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text14").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A13=="         check" && A14!="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text14").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A14=="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text15").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A14=="         check" && A15!="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text15").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A15=="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text16").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A15=="         check" && A16!="         check" && A17!="         check" && A18!="         check") this.getField("Text16").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A16=="         check" && A17!="         check" && A18!="         check") this.getField("Text17").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A16=="         check" && A17!="         check" && A18!="         check") this.getField("Text17").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A17=="         check" && A18!="         check") this.getField("Text18").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A17=="         check" && A18!="         check") this.getField("Text18").value=J1+", check ("+num1+")"+" "+al+" with info :"

if (num!=0 && A18=="         check") this.getField("Text19").value=J1+", check ("+num+")"+" "+hm+" "+"and"+" "+"("+num1+")"+" "+al+" with info :"

if (num==0 && A18=="         check") this.getField("Text19").value=J1+", check ("+num1+")"+" "+al+" with info :"

try67
Community Expert
Community Expert
November 18, 2018

Yes, you can use a simple loop to do it, and there's also no reason to check all the fields because as soon as one of them does not equal the value you're comparing it to then you can stop. However, that can only work if the condition is the same for each field.

What is "num1" and what does it have to do with the rest of the fields, and why is the condition for A0 different for all the rest? Is it the same for 1-500 and only different for 0?

If so, you can use something like this:

var b = (num1!=0 && this.getField("Dropdown14.0").valueAsString=="check");

if (b==true) {

    for (var i=1; i<=500; i++) {

         var f = this.getField("Dropdown14."+i);

         if (f.valueAsString=="check") {

             b=false;

             break;

         }

    }

}

if (b==true) {

    // do something

} else {

    // do something else

}

Karl Heinz  Kremer
Community Expert
Community Expert
November 18, 2018

Try67 gave some good ideas on how to solve your problem. I’d like to show you another option. You can store your field values in an array, and then use a calculated array index to reference them:

var A =[];

for (var i=0; i<500; i++) {

    A = this.getField(“Dropdown.14.” + i).value;

}

You can then reference any A value in the array using a loop.