No announcement yet.

Multidimensional array elements remains undefined

  • Filter
  • Time
  • Show
Clear All
new posts

  • Multidimensional array elements remains undefined


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

    	var i = 0
    	while( {
    		sql = "update "+dbTable+" SET Imported = 1, LastTimeStamp = LNKTIMESTAMP where IncrementIndex = "+result.getString("IncrementIndex")+";"
    		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")
    The result sets come out of mysql.

    If I put a directly under the definition e.g.
    OrderInfo[i]["Order_ID"] = result.getString("Order_ID")[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

    for (o in OrderInfo)["Order_ID"])
    i still get undefined...

    somehow, this works:
    for (var i = 0; i < OrderInfo.length; i++) {
    	for (var o in OrderInfo[i])[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.


    • #3
      The 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 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:
      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.