Announcement

Collapse
No announcement yet.

MIRTH channel to move PDF files

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

  • MIRTH channel to move PDF files

    Hi

    So I'm new to MIRTH in many ways! So I need some help.

    I need to watch a folder where PDF files will be written, the first part of the PDF filename (up to an underscore) will be the name of a folder where I want mirth to move the PDF to

    E.G.

    c:\pdf is the watched folder
    c:\folder1
    c:\folder2 are the destination folders

    These files will appear

    c:\pdf\folder1_thisismypdf.pdf
    c:\pdf|folder2_thisisanotherpdf.pdf

    I want the mirth channel to parse the filename, figure out which folder it should move the PDF to, and then do so

    I am using a simple File Reader source connecter to watch c:\pdf, and want to use the MoveToDirectory part to move the file, and I am using javascript to put the first part of the filename into a variable (folder_name) in the Source Transformer.

    How can I use my variable folder_name in the MoveToDirectory dialogue box?

    Or is this impossible?
    Is there another way to achieve this?
    Should be pretty simple right?

    Thanks

    MRobz

  • #2
    There will be variables in the channel. The one you want is...

    ${originalFilename}

    var index = ${originalFilename}.toString().indexOf('_');

    var folder = ${originalFilename}.toString().substring(index + 1, ${originalFilename}.toString().length());

    Comment


    • #3
      Hi Cory
      Thanks for the reply!

      Actually that's the part I have achieved - what i don't know is how to use that variable in the Move File part

      Source - File Reader
      After Processing Action - Move
      Move-to-directory - here I need to use my variable to define the folder

      This is the part I don't understand
      If I put my variable name in there like this c:\${folder}
      the channel simply creates a folder called ${folder}

      Comment


      • #4
        Do it in the transformer. Then do a channelMap.put(key, value). Then the key will be available as variable.

        Depends on how you are doing it. If you are creating the variable in javaScript, the variable name is just folder not ${folder};
        Last edited by cory_cole; 06-19-2019, 12:02 PM.

        Comment


        • #5
          Hi again Cory

          So in my Source Transformer I have a JavaScript entry like this;

          var file_name = $('originalFilename');
          var parts = file_name.split('_');
          var folder = parts[0];
          ChannelMap.put('folder',folder);


          In the After Processing Move To Directory dialogue box I have this;
          c:/pdf/${folder}

          But when I run the channel it just creates a folder literally called c:/pdf/${folder} and moves the files into it


          I guess I am messing up somewhere?
          I'm doing everything in the Source Tab as it feels like it should be quite simple

          Comment


          • #6
            So it looks like I cant use a Channel Mapping in that place in the Source part
            My mapping called "folder" does show up on the list of mappings on the Destination tab

            So I am trying to use File Writer to write the PDF into the new folder, but I can't figure that out either

            It always wants me to put a template in at the bottom, I just want to write the original file to a different folder

            Comment


            • #7
              You shouldn't have to use the template. It is just there if you need it.

              Comment


              • #8
                This is all a good excercise to learn about how mirth works, but it would be much more efficient to do this with a shell script or using javascript/java to do the file moves. A File Reader needs to read in the entire contents of the file, which doesn't seem to be a requirement for you.

                If you want to use a File Writer, use ${message.encodedData} as your template. The encoded data is the output from your transformer, which is the same as the input if you don't modify it.

                Comment


                • #9
                  Thanks for your help!
                  So it all kind of functions except that my original PDF file is 49Kb and the new one that is written is 1Kb and unreadable -
                  Any idea what I've missed here?

                  Comment

                  Working...
                  X