Forum Discussion

hina's avatar
hina
Contributor
4 months ago
Solved

Length of Array is returned as undefined

Hi,

For the code below, the length of Array is returned undefined, even though the Array is not empty. I have tried using both "length" and "Count" to get the length of Array but it is returning undefined for both. Please help me figure out what I am missing, I don't see anything wrong with the code.

function Test1()
{
  var AppProcess = Sys["WaitProcess"]("AXISEL");
  
  var ArrProps = new Array("Description","ObjectType");
  var ArrVals = new Array("*Batch Name: GlaaS Post Job Submission*","ListItem");
  
  var ListJob = AppProcess["FindAllChildren"](ArrProps,ArrVals,1000);
  
  var ArrLength1 = ListJob.length;
  var ArrLength = ListJob.Count;
  
  ListJob[ArrLength - 1].Click();
  Delay(1000);
}

  • I haven't tested the code, but could you replace the code with this, to see if it logs the length of ListJob.

    var ListJob = AppProcess["FindAllChildren"](ArrProps,ArrVals,1000);
    
    // Replace the above with this
    
    var ListJob = AppProcess["FindAllChildren"](ArrProps, ArrVals, 1000)["toArray"]();
    Log["Message"]("Total number of ListJob: " + ListJob["length"]);
    

     

4 Replies

  • It's hard to understand what you are doing and have no idea where to begin to help you debug. The issue you're encountering return undefined, suggests that ListJob is not an array or an object that has properties (length or Count). Instead, it seems like ListJob may be some other type of object that doesn't directly support these properties.

    Use ChatGPT to ask your question as you posted it, it will provide you with suggestion and recommendation on how to debug this code.

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    I haven't tested the code, but could you replace the code with this, to see if it logs the length of ListJob.

    var ListJob = AppProcess["FindAllChildren"](ArrProps,ArrVals,1000);
    
    // Replace the above with this
    
    var ListJob = AppProcess["FindAllChildren"](ArrProps, ArrVals, 1000)["toArray"]();
    Log["Message"]("Total number of ListJob: " + ListJob["length"]);
    

     

    • hina's avatar
      hina
      Contributor

      Hi rraghvani,

      Thank you so much for your response, converting it toArray worked!! 

      Thanks,

      Hina

      • rraghvani's avatar
        rraghvani
        Icon for Champion Level 3 rankChampion Level 3

        I haven't touched C++ for many years, so I am a bit rusty with C++ coding!

        Without ["toArray"]() it will return a memory reference of the object. So you need ["toArray"]() to convert to an array of objects. You can access object properties such as length of the array via ["length"]

        JavaScript is less complicated and easier to understand. C++ is very old now.