web stats
File Writer - Quick Question - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-01-2018, 07:45 AM
jcurry5 jcurry5 is offline
OBX.2 Kenobi
 
Join Date: May 2013
Posts: 59
jcurry5 is on a distinguished road
Default File Writer - Quick Question

I have a simple channel that the Source queries a SQL database which returns x number of rows.

The Destination is a File Writer that has 3 transform steps (no JS code) that maps the 3 data elements from the Source query.

The Template is just a simple pipe delimited that maps to the 3 data elements. The problem I'm running into figuring out is the following:

1) Append works and appends all of the accounts but the next time that the channel polls/runs, it'll append to the file with duplicate records. I set the File Exist to Overwrite but it overwrites the file from each record so only the last record will be on the file.

Is there no setting in Mirth that will aggregate all of the records into the file with the Overwrite option set?

If I have to use JS I will but just trying to keep this as simple and clean as possible using Mirth options.

Thanks.
Reply With Quote
  #2  
Old 03-01-2018, 08:20 AM
aTom aTom is offline
OBX.3 Kenobi
 
Join Date: Feb 2016
Location: Lake Geneva Area
Posts: 115
aTom is on a distinguished road
Default

Hi

In 3.5.x you have an "Aggregate results" option on your connector that will deliver one single message <results><result>...</result></results>. Then you'll have to use an Iterator step in your transformer to handle each result individually.

Otherwise you have to make sure that your data is retrieved only once from your db, using accurate update query.
__________________
Tom
Reply With Quote
  #3  
Old 03-07-2018, 11:26 AM
jcurry5 jcurry5 is offline
OBX.2 Kenobi
 
Join Date: May 2013
Posts: 59
jcurry5 is on a distinguished road
Default

So I have the aggregate results set to true and created a javascript step but it still appends to the file or overwrites based on the selection for output.

Quote:
var length = msg['result'].length();

for (i=0; i<length; i++)
{
var mrn;
var pcn;
var facilityID;
var upload;

mrn = msg['result'][i]['mrn'].toString();
pcn = msg['result'][i]['pcn'].toString();
facilityID = msg['result'][i]['facilityid'].toString();

upload = mrn+"|"+pcn+"|"+facilityID;
channelMap.put('upload',upload);
}
This is the javascript code so I'm guessing I can't use this as it'll use whichever radio option you have selected.

Is there a way to perform the following:

Query a sql database
Get list of records/data elements
If the file c:\test.txt exist, overwrite it when the channel polls with the latest data from the query
Else create a new file with the data from the query

Thanks.
Reply With Quote
  #4  
Old 03-07-2018, 12:11 PM
jcurry5 jcurry5 is offline
OBX.2 Kenobi
 
Join Date: May 2013
Posts: 59
jcurry5 is on a distinguished road
Default

So after messing around with some simple JS code I was able to get this done without much effort.

Quote:
var length = msg['result'].length();
var output ='';

for (i=0; i<length; i++)
{
var mrn;
var pcn;
var facilityID;
var upload;

mrn = msg['result'][i]['mrn'].toString();
pcn = msg['result'][i]['pcn'].toString();
facilityID = msg['result'][i]['facilityid'].toString();

upload = mrn+"|"+pcn+"|"+facilityID;

output = upload+"\r\n"+output;

channelMap.put('upload',output);
}
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 03:25 AM.


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