Skip to Content
Author's profile photo Praveen Gandepalli

Multi Mapping with Dynamic FileName and Dynamic Folder using Variable Substitution

Introduction

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.

Approach

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.
CCContentConversion.png

Scenario

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.


Design

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.

ORDERS05.pngStockOrder.png

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.

/wp-content/uploads/2016/01/mapping_signature_861483.png

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.

/wp-content/uploads/2016/01/mapping_861478.png

The below is FileName field mapping, IDoc number concatenate with ‘.txt’ extension.

fileNameMapping.png

Configuration

The below is receive file communication channel configuration, target directory and target file name with variables created under variable substitution section.

CCtarget.png

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.

CCContentConversion.pngOrderHeader.png

OrderItem.png

The below is ‘fname’ and ‘plant’ variables which we used in target directory and file name.

CCAdvanced.png

Testing Results

The below is input payload, there are two IDocs with same plant(3204), so at the end we expect two dynamic folders.

inputPayload.png

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)

messageMoni.png

We can see IDoc number and the plant number are mapped under File node in the target payload.

/wp-content/uploads/2016/01/payload_861503.png

We can see in the audit log the variables plant and IDoc number are replaced at runtime.

/wp-content/uploads/2016/01/auditlog_861504.png

As we expect the two folders created under target directory.

/wp-content/uploads/2016/01/floders_861505.png

We can find two files under 3204 directory (source file contains two IDocs with same plant 3204)

/wp-content/uploads/2016/01/3204_861506.png

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.

FileContent.png

And one file under 3205 folder.

/wp-content/uploads/2016/01/3205_861507.png

References

A new approach: Multi-mapping Dynamic Configuration using a generic custom module

Multi-mapping with Dynamic Configuration – SOAP loopback approach

Conclusion

With this approach we can still achieve dynamic file name and folder even we use multi mapping, i hope this will be helpful.

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Nice blog.  well explained. Thank you.

      Author's profile photo Former Member
      Former Member

      Good one Praveen....Thanks for sharing

      Author's profile photo Former Member
      Former Member

      Excellent, very useful blog.

      Author's profile photo Eng Swee Yeoh
      Eng Swee Yeoh

      Hi Praveen,

      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.)

      Rgds

      Eng Swee

      Author's profile photo Praveen Gandepalli
      Praveen Gandepalli
      Blog Post Author

      Hi Eng,

      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.

      Regards,

      Praveen.

      Author's profile photo Former Member
      Former Member

      Very good and helpful blog.

      Author's profile photo Gov TOTAWAR
      Gov TOTAWAR

      Nice one Praveen 🙂

      Author's profile photo Ashok Kumar
      Ashok Kumar

      Hi 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\.