IT Process Automation

 View Only

Javascript for/in loop issue with process dataset items

  • 1.  Javascript for/in loop issue with process dataset items

    Posted Jun 15, 2023 03:55 AM

    Hello,

    I'm using a Run Javascript operator with the following code as an example:

    var logging = true;
    
    function log(sLogEntry) {
      if (logging) Process._DEBUG += sLogEntry + "\n";
    }
    
    typeOfStringArraySingle = typeof(Var_String_Array_Single);
    log("Type of Var_String_Array_Single = " + typeOfStringArraySingle);
    for (var key in Var_String_Array_Single) {
      if (true) log(key + " = " + Var_String_Array_Single[key]);
    }

    This gives me no errors but never enters the for loop. I also tried logging a static string value.

    On the other hand if I run this:

    var logging = true;
    
    function log(sLogEntry){
      if (logging) 
    	Process._DEBUG += sLogEntry + "\n";
    }
    
    var myArray = [];
    myArray.push("Test 01");
    myArray.push("Test 02");
    for (var key in myArray)
      if (true) log(key + " = " + myArray[key]);
    
    var myArray2 = new Object();
    myArray2["foo"] = "Nin";
    myArray2["bar"] = "ja!";
    for (var key in myArray2)
      if (true) log(key + " = " + myArray2[key]);
    

    This works perfectly as expected.

    Certainly I'm doing something wrong or I have wrong expectations on the Process Dataset.
    Can anyone explain the right approach for this?

    Regards,

    Armado Martires