Don't Pair Regex Trigger Actions With A Directory Monitor Event

Pairing regex-type trigger actions with a directory monitor event can result in outcomes that aren't in line with your intention. Learn more at JSCAPE.
  1. Blog

When sever admins pair regex-type trigger actions (e.g. Trading Partner Regex File Upload) with a directory monitor event (e.g. Directory Monitor File Added) on JSCAPE MFT Server, the usual intention is to apply the action on the file(s) that was/were detected by the directory monitor. If so, this course of action (pun intended) isn't the right way to do it.

Note: There may be specific use cases when you may pair regex type actions with a directory monitor event but these are more exceptions than the rule.

Let me show you a concrete example to illustrate what I mean. Let's say you have a directory monitor monitoring a directory for new files and you want all files that come in to be uploaded to a trading partner.

directory_monitor_auto_upload_files-2

If you don't analyze it deeply, one possible strategy you might come up with is to add a trigger that:

1. Listens to the Directory Monitor File Added event, and

2. Fires off a Trading Partner Regex File Upload action that uses the *.* wildcard or .* regular expression

This would seem like a logical strategy because the regular expression will upload all files that match the expression in the directory, which is every single file in this case. However, that's where the problem lies.

You won't encounter any issues when the first file comes in. The file comes in, the directory monitor detects it, the DM raises a Directory Monitor File Added event, the trigger catches that event, and then the trigger responds by running the Trading Partner Regex File Upload action.

Because there's only one file in the directory (the file that just came in), that single file will match the *.* wildcard, and it will be uploaded to the trading partner.

But then what if a second file comes in (it doesn't matter if it's a few minutes after or a split-second after)?

Ok. The second file comes in, the directory monitor detects it, the DM raises a Directory Monitor File Added event, the trigger catches that event, and then the trigger responds by running the Trading Partner Regex File Upload action.

This time, because there are now two files in the directory (the file that just came in and the other file that came in earlier), those two files will match the *.* wildcard, and both files will be uploaded to the trading partner.

Same thing happens when a third file comes in, or a fourth, or a fifth. and so on. EACH time a new file comes in, ALL files in the directory will be uploaded to the trading partner. And it doesn't matter what wildcard or regular expression you use. Each time a file comes in, ALL files that match the regular expression will be uploaded. As a result, your trading partner will receive multiple copies of the same files.

Use non-regex type actions instead

To avoid these types of issues, we suggest you use non-regex type actions for this purpose instead. So, for example, instead of pairing a Trading Partner Regex File Upload with a directory monitor, use a Trading Partner File Upload. Or instead of pairing a Move Regex File action, just use a Move File action.

This will ensure that only the files that just came in are acted upon by the trigger action. If we go back to our example above β€” if you use a Trading Partner File Upload instead of a Trading Partner Regex File Upload, only the file that just came in will be uploaded to the trading partner.

Now, you might be thinking β€” but we want all files that come in to be uploaded. That's exactly what the trigger will do. It might seem that it's only uploading a single file. But because it's uploading EVERY SINGLE FILE THAT COMES IN, it's actually uploading all files that come in. No file that satisfies the regex is left out.

Now, to make sure it does just that, you need to enter the %LocalPath% variable (or %File% variable, they're the same) into the Local File or File field of whatever trigger action you're using in lieu of the regex type action. When that trigger action is used in conjunction with a Directory Monitor type of event, the %LocalPath% will contain the complete path of the file that was detected by the DM.

Again, going back to our example earlier, if the directory monitor detects a newly added file, the complete path of that newly added file will be stored in the %LocalPath% variable. So, if you use that variable in the Local File field of the Trading Partner File Upload action, the trigger will upload specifically that file that just came in. And it will do that for every single file that comes in.

trading partner file upload-2

For more concrete examples, read these posts:

Monitoring A Remote SFTP Server for Newly Added Files

How to Download Newly Added Files from an AWS S3 Folder

Auto Upload Files To A Remote Server Upon Arrival At A Local Directory

How To Set Up An Automated AS2 File Transfer

Try this yourself

Would you like to try this yourself? Download the FREE, fully-functional Starter Edition of JSCAPE MFT Server now. Download Now