Multi Mapping with Dynamic FileName and Dynamic Folder using Variable Substitution
As we all know if we use multi mapping we cannot set dynamic file name and folder with dynamic configuration because same header is shared by all the messages,Recently there are many threads asking about this requirement, If the fields used in variable substitution are part of the target payload then dynamic file name or folder is not a problem, only those fields are not part of the target payload then we cannot use variable substitution for dynamic file name and folder but in this blog i will show you how to achieve this using variable substitution.
We will add separate node under target structure to hold the fields which are used in variable substitution and these fields are not part of the target file, we will use below content conversion parameters for this node and then file adapter will ignore this record at runtime.
The scenario is we get one message with multiple orders and we need to generate multiple files at the target side with each file containing single order. We need to create dynamic folders based on plant field in the source message, we need to create dynamic file name with IDoc number.
The below are sender and receiver data types used in this scenario, for simplicity i have created the own data type for IDoc, i have added separate node called ‘File’ under target structure, FileName(this field used in dynamic file name) and plant(this field used in dynamic folder) are fields under this node, these fields will be used in variable substitution in the receiver file channel in the directory.
As we are creating multiple files from single IDoc we need to change the occurrence of receiver message to unbounded under signature part of the mapping.
The below is mapping between source message and target message, all fields are simple field to field mapping, we will receive multiple IDOC nodes in source message and i am creating multiple StockOrder nodes in target side. DOCNUM (Idoc number) and WERKS i am not passing to the target file, we need these fields to set dynamic file name and folder so we need to map these two fields under File node in the target structure.
The below is FileName field mapping, IDoc number concatenate with ‘.txt’ extension.
The below is receive file communication channel configuration, target directory and target file name with variables created under variable substitution section.
The below is content conversion for receiver file, As we don’t need to send the fields under File node to the target file we need to use below parameters to ignore these fields in the target file.
The below is ‘fname’ and ‘plant’ variables which we used in target directory and file name.
The below is input payload, there are two IDocs with same plant(3204), so at the end we expect two dynamic folders.
The below are four messages in message monitor, one for sender to messaging system, three message for messaging system to receiver(as per our multi mapping one file split into three messages)
We can see IDoc number and the plant number are mapped under File node in the target payload.
We can see in the audit log the variables plant and IDoc number are replaced at runtime.
As we expect the two folders created under target directory.
We can find two files under 3204 directory (source file contains two IDocs with same plant 3204)
The below one of the file content, We can see the IDoc number and plant values are not part of the file, only it contains header and item of the order.
And one file under 3205 folder.
A new approach: Multi-mapping Dynamic Configuration using a generic custom module
Multi-mapping with Dynamic Configuration – SOAP loopback approach
With this approach we can still achieve dynamic file name and folder even we use multi mapping, i hope this will be helpful.
Nice blog. well explained. Thank you.
Good one Praveen....Thanks for sharing
Excellent, very useful blog.
Nice trick configuring the FCC parameters to ignore the additional record type! Thanks for sharing this.
A few thoughts on some limitations for this - can you confirm?
- Only applies for scenarios where FCC is used in receiver channel, so target XML payloads can't use this
- If I'm not mistaken, it will not work if FCC is achieved via modules (i.e. MessageTransformBean) because variable substitution will not work in those cases (example SFTP File Content Conversion Error:The variable substitution can not parse the message xml: Content is not allowed in prolog.)
Thanks for the comment, Yes this will not work if we use module for FCC, But SFTP adapter also included the same FCC as File adapter, so we no need to use modules for FCC in SFTP adapter.
Very good and helpful blog.
Nice one Praveen 🙂
Is it possible to trim source file name and used same as variable to the target directory for pick and drop scenarios?
EX: If source file name is ABC-123.xml, then target directory is Customer\ABC\Inbox\.
for XYZ-789.xml file name, target directory is Customer\XYZ\Inbox\.