web stats
Insert an Array into db using JavaScript - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-21-2011, 12:06 PM
DimitriA DimitriA is offline
Mirth Newb
 
Join Date: Jul 2011
Posts: 17
DimitriA is on a distinguished road
Default Insert an Array into db using JavaScript

Hi,

I'm trying to use JavaScript to insert an array of integers into a db. Unfortunately, I'm not getting the syntax right and they're appearing as strings

I can get the string patientID to INSERT correctly, but the resultVal integers appear as strings as well, throwing an error. How can I make resultVal[count] an integer?

Code:
for (count=0; count< $('resultVal').length; count++)
{
	query = CDRUpdate("INSERT INTO resultValues (patientID, value) VALUES ('"+$('patientID')+"', '"+$('resultVal')[count]+"')");
}
Any ideas? I've also tried using a "for each" loop but couldn't get that to work either. If you know how to do either one, it'd be much appreciated.

Last edited by DimitriA; 07-21-2011 at 12:17 PM.
Reply With Quote
  #2  
Old 07-21-2011, 01:47 PM
marmanold marmanold is offline
Mirth Newb
 
Join Date: Feb 2011
Location: Franklin, TN
Posts: 9
marmanold is on a distinguished road
Default

I'm not sure which database back end you're using, but I would put a CAST or CONVERT statement around the integer value in the INSERT statement. For example:
Code:
INSERT INTO database.dbo.myTable (id, int_value) VALUES(2, CAST('001' AS INTEGER));
__________________
Michael Arnold| Electronic Data Interchange Specialist

PlayMaker CRM
Sales Innovation for Home Care
A Division of The ADAM Group
115 Southeast Parkway Court | Franklin, TN 37064
866.930.6847 | F: 866.232.6470 | PlayMakerCRM.com
Reply With Quote
  #3  
Old 07-21-2011, 02:41 PM
DimitriA DimitriA is offline
Mirth Newb
 
Join Date: Jul 2011
Posts: 17
DimitriA is on a distinguished road
Default

I got it. Thank you!
Reply With Quote
Reply

Tags
javascript, transformer

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 09:55 AM.


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