web stats
Multidimensional array elements remains undefined - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 04-29-2014, 01:21 AM
gkittlaus gkittlaus is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Posts: 104
gkittlaus is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 04-29-2014, 01:54 AM
gkittlaus gkittlaus is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Posts: 104
gkittlaus is on a distinguished road
Default

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 at 02:10 AM.
Reply With Quote
  #3  
Old 04-29-2014, 07:22 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 11:05 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation