Sidebar

Can I increment my file name on a destination.

0 votes
285 views
asked Apr 20, 2016 by brandon-w-8204 (29,750 points)
edited Apr 20, 2016 by brandon-w-8204
I need to have unique file names on a channel. Files are picked up how can I make sure the name is unique when sending on destnation node.

1 Answer

+1 vote

There is a few ways to make a unique filename.

1. Use a UUID Node Tag "{UUID}" in the Path. Example: c:\temp\{UUID}.txt

2. Increment a number to a base file name for every message processed. To make sure this is always right "First in First Out" is needed to be set in Channel Properties:

a. Create a mapping to lookup the last number used and increment it by one then store it in the Message Cache. Here is the code used in the mapping function.

var fileNameInstance = channelCache.getValue('fileNameInstance') *1;
if (fileNameInstance === 0) {
   fileNameInstance++;
}
messageCache.setValue('fileNumber', fileNameInstance);
fileNameInstance++;
channelCache.setValue('fileNameInstance', fileNameInstance);
 

b. Use the Message Cache in a node tag "{mc:fileNumber}" in the destination node. Example: c:\temp\baseName{mc:fileNumber}.txt

answered Apr 20, 2016 by brandon-w-8204 (29,750 points)
edited Apr 20, 2016 by brandon-w-8204
...