web stats
MIRTH channel to move PDF files - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-19-2019, 11:09 AM
mrobz mrobz is offline
What's HL7?
 
Join Date: Apr 2016
Location: Brighton, UK
Posts: 5
mrobz is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 06-19-2019, 11:21 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,282
cory_cole is on a distinguished road
Default

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());
Reply With Quote
  #3  
Old 06-19-2019, 11:53 AM
mrobz mrobz is offline
What's HL7?
 
Join Date: Apr 2016
Location: Brighton, UK
Posts: 5
mrobz is on a distinguished road
Default

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}
Reply With Quote
  #4  
Old 06-19-2019, 12:00 PM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,282
cory_cole is on a distinguished road
Default

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 at 12:02 PM.
Reply With Quote
  #5  
Old 06-19-2019, 12:11 PM
mrobz mrobz is offline
What's HL7?
 
Join Date: Apr 2016
Location: Brighton, UK
Posts: 5
mrobz is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 06-19-2019, 12:43 PM
mrobz mrobz is offline
What's HL7?
 
Join Date: Apr 2016
Location: Brighton, UK
Posts: 5
mrobz is on a distinguished road
Default

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
Reply With Quote
  #7  
Old 06-20-2019, 05:33 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,282
cory_cole is on a distinguished road
Default

You shouldn't have to use the template. It is just there if you need it.
Reply With Quote
  #8  
Old 06-20-2019, 10:05 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 965
agermano is on a distinguished road
Default

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.
Reply With Quote
  #9  
Old 06-23-2019, 02:23 PM
mrobz mrobz is offline
What's HL7?
 
Join Date: Apr 2016
Location: Brighton, UK
Posts: 5
mrobz is on a distinguished road
Default

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?
Reply With Quote
Reply

Tags
file, move, pdf

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 11:05 AM.


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