Announcement

Collapse
No announcement yet.

Multidimensional array elements remains undefined

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multidimensional array elements remains undefined

    Hi,

    I am using MC 2.2.3 currently.
    In my filter I define an array like this:

    Code:
    	var i = 0
    	while(result.next()) {
    		sql = "update "+dbTable+" SET Imported = 1, LastTimeStamp = LNKTIMESTAMP where IncrementIndex = "+result.getString("IncrementIndex")+";"
    		dbConn.executeUpdate(sql);
    
    		OrderInfo = new Array();
    		OrderInfo[i] = new Object();
    		OrderInfo[i]["Order_ID"] = result.getString("Order_ID")
    		OrderInfo[i]["Order_Provider"] = result.getString("Order_Provider")
    		OrderInfo[i]["Order_TestsID"] = result.getString("Order_TestsID")
    		OrderInfo[i]["Order_TestsText"] = result.getString("Order_TestsText")
    		OrderInfo[i]["Order_DateTime_Scheduled"] = result.getString("Order_DateTime_Scheduled")
    		OrderInfo[i]["Order_DateTime_Transaction"] = result.getString("Order_DateTime_Transaction")
    		i++
    	}
    The result sets come out of mysql.

    If I put a logger.info directly under the definition e.g.
    Code:
    OrderInfo[i]["Order_ID"] = result.getString("Order_ID")
    logger.info(OrderInfo[0]["Order_ID"])
    it works

    if I try the same outside the while loop, the array is undefined and I get an error.

    any ideas?

  • #2
    sometimes I wanna slap myself
    I put the definition of the array in the loop... again a thread wasted

    ok, anyhow... if I now do

    Code:
    for (o in OrderInfo) logger.info(o["Order_ID"])
    i still get undefined...

    somehow, this works:
    Code:
    for (var i = 0; i < OrderInfo.length; i++) {
    	for (var o in OrderInfo[i]) logger.info(OrderInfo[i][o])
    }
    but that's not what I want. I want to call elements by their property's name

    EDIT: damnit, it works now. With the for loop instead of the for each it works...
    Last edited by gkittlaus; 04-29-2014, 01:10 AM.

    Comment


    • #3
      The for..in loop iterates through each enumerable property of the given object. The funny thing about native JavaScript arrays is that the element indices are the property names, so for (var o in OrderInfo) will assign 0, 1, etc. to the variable "o". The for..each..in loop (specified in E4X) is different because it assigns the value of each enumerable property to the LHS iteration variable (essentially the range or value set of the given object, rather than the domain or key set). More info here:

      http://www.ecma-international.org/pu...T/Ecma-262.pdf
      http://www.ecma-international.org/pu...T/Ecma-357.pdf
      Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

      Nicholas Rupley
      Work: 949-237-6069
      Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


      - How do I foo?
      - You just bar.

      Comment

      Working...
      X