Announcement

Collapse
No announcement yet.

File Writer - Quick Question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    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

    Comment


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

      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.

      Comment


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

        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);
        }

        Comment

        Working...
        X