web stats
Need to store the database result in a variable so that I can use the variable - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 10-13-2017, 02:17 AM
lovelate lovelate is offline
Mirth Newb
 
Join Date: Sep 2017
Posts: 11
lovelate is on a distinguished road
Exclamation Need to store the database result in a variable so that I can use the variable

Hello ,
I am working on a requirement where in I am running a query with the help of javascript and now i am stuck.

I want to store the output of that query into a variable so that I can use the same variable to other destinations. Following is the script that i have written

var dbConn;
var insID;
var pid = $('PID');
//logger.info(pid);

{
dbConn = DatabaseConnectionFactory.createDatabaseConnection ('org.postgresql.Driver','jdbcostgresql://localhost:5432/mirthdb','postgres','27483914');


var sql = "SELECT insuranceid FROM public.insurance where patientid = '+pid+'";

I want to store the output of this query into a variable. Can you p lease help me with the same.
Reply With Quote
  #2  
Old 10-13-2017, 05:48 AM
stormcel stormcel is offline
OBX.3 Kenobi
 
Join Date: Mar 2010
Location: Phoenix
Posts: 154
stormcel is on a distinguished road
Default

This should work, it's a basic skeleton for handling query results.
note: you can expand on this to process more results.
each result will be result.getString(1) then result.getString(2) etc
will be the values from multiple columns in the result, then it will loop to the next row of the result.
Code:
var dbConn;
var insID;
var pid = $('PID');
//logger.info(pid);

dbConn = DatabaseConnectionFactory.createDatabaseConnection('org.postgresql.Driver','jdbc:postgresql://localhost:5432/mirthdb','postgres','27483914');


var sql = "SELECT  insuranceid FROM public.insurance where patientid = '+pid+'";

  result = dbConn.executeCachedQuery(sql);    //Run the query and get the results 
    var cnt = result.size();    //get the number of rows returned in the query 
    for (i = 0; i < cnt; i++) {     //loop it up 
        result.next();      //go to the first row     
     
        var foundInsuranceID = result.getString(1);    //get the first item in the results 
    }
Reply With Quote
  #3  
Old 10-13-2017, 06:15 AM
lovelate lovelate is offline
Mirth Newb
 
Join Date: Sep 2017
Posts: 11
lovelate is on a distinguished road
Default

!!Thank you !!
Reply With Quote
Reply

Tags
database, variable

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 12:33 AM.


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