Question

I have a file reader channel picking up an xml document. By default, a file reader channel populates the 'originalFilename' in the channel map, which ony gives me the name of the file, not the full path. Is there any way to get the full path, withouth having to hard code something?

Was it helpful?

Solution

Unfortunately, there is no variable or method for retrieving the file's full path. Of course, you probably already know the path, since you would have had to provide it in the Directory field. I experimented with using the preprocessor to store the path in a channel variable, but the Directory field is unable to reference variables. Thus, you're stuck having to hard code the full path everywhere you need it.

OTHER TIPS

You can get any of the Source reader properties like this:

var sourceFolder = Packages.com.mirth.connect.server.controllers.ChannelController.getInstance().getDeployedChannelById(channelId).getSourceConnector().getProperties().getProperty('host');

I put it up in the Mirth forums with a list of the other properties you can access http://www.mirthcorp.com/community/forums/showthread.php?t=2210

You could put the directory in a channel deploy script:

globalChannelMap.put("pickupDirectory", "/Mirth/inbox");

then use that map in both your source connector:

${pickupDirectory}

and in another channel script:

function getFileLastModified(fileName) {
   var directory = globalChannelMap.get("pickupDirectory").toString();
   var fullPath = directory + "/" + fileName;
   var file = Packages.java.io.File(fullPath);
   var formatter = new Packages.java.text.SimpleDateFormat("yyyyMMddhhmmss"); 
   formatter.setTimeZone(Packages.java.util.TimeZone.getTimeZone("UTC")); 
   return formatter.format(file.lastModified()); 
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top