Announcement

Collapse

Mirth Connect 4.3.0 Released!

Mirth Connect 4.3.0 is now available as an appliance update and on our GitHub page.

This is a major release containing new features like adding new functionality to the Mirth Connect Setup Wizard, adding the ability for resource and channel-specific classloaders to load child-first or parent-first, and added a default implementation of the getObjectsForSwaggerExamples() method in the ServicePlugin class. This release also contains enhancements for the Mirth Connect Administrator Launcher, the Mirth Connect Docker images, and several bug fixes and security improvements.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

CSV file output error

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

  • CSV file output error

    Hi Everyone,

    I have to read a CSV file form a directory, do some data validation and then send the valid rows to a CSV file (valid.csv) and errored rows to another CSV file (errored.csv). I have created one source transformer and two destination transformers in my channel. The source transformer validates the rows and sends an array of indexes of errored rows to both destination transformers. The first destination transformer outputs the valid rows on valid.csv and the second one on errored.csv. I am getting the following error when trying to output the valid rows in tmp object in destination transformer. I have set up an out bound message template. I am using Mirth 4.1.1.

    DESTINATION TRANSFORMER CODE

    //indexes of errored rows from source transformer
    var errorIndices = new Array;
    errorIndices = $('ErrorInd');


    var numOfColumn = msg.row[0].children().length();
    var a = 0;

    //Adding valid rows

    for(var i=0;i<msg['row'].length();i++)

    {
    if (errorIndices.includes(i) == false){
    for(var j=1;j<=numOfColumn;j++){
    var tmp;
    tmp['row'][a]['column'+j] = msg['row'][i]['column'+j].toString();
    a++;

    }
    }​
    ​}





    ERROR:


    SCRIPT SOURCE: TRANSFORMER
    SOURCE CODE:
    283: {
    284: if (errorIndices.includes(i) == false){
    285: for(var j=1;j<=numOfColumn;j++)
    286: {
    287: var tmp;
    288: tmp['row'][a]['column'+j] = msg['row'][i]['column'+j].toString();
    289: a++;
    290:
    291: }
    292: }
    LINE NUMBER: 288
    DETAILS: TypeError: Cannot read property "row" from undefined
    at 362ab486-cd1a-4405-a615-66dd64f020d4_JavaScript_Filter_Transformer_1:288 (doTransform)
    at 362ab486-cd1a-4405-a615-66dd64f020d4_JavaScript_Filter_Transformer_1:468 (doScript)
    at 362ab486-cd1a-4405-a615-66dd64f020d4_JavaScript_Filter_Transformer_1:470
    at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:235)
    at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:187)
    at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:114)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
    at java.lang.Thread.run(Unknown Source)



    I can post the whole channel if required. Any help would be appreciated. Thanks.

  • #2
    I would not use "tmp" as a var name, that is an existing construct in mirth.

    But post your full channel.
    Diridium Technologies, Inc.
    https://diridium.com

    Comment


    • #3
      Thank you very much for looking into this. I have attached the channel and a test csv below. Please let me know if you have any questions or need any additional information.

      Col1 ,Col2,Col3,Col4
      AA,BB,CC,DD
      EE,FF,GG,HH
      II,JJ,KK,LL
      MM,NN,OO,PP
      Attached Files

      Comment


      • #4
        Here is an example keeping the rows you want:

        image.png
        image.png
        image.png

        Thanks for following the forum guidelines and posting your code attempt!​
        Last edited by pacmano; 02-05-2023, 07:42 AM.
        Diridium Technologies, Inc.
        https://diridium.com

        Comment


        • #5
          That is awesome!!! Exactly the solution I was looking for and thank you for showing how to use the tmp object correctly. Really appreciate your help with this!

          Comment

          Working...
          X