Change EDI Separators & Delimiters for Incoming Documents

Document created by mitchell_beyer681766 on Jul 26, 2018Last modified by thanh_n88 on Jul 31, 2018
Version 2Show Document
  • View in full screen mode

It is not uncommon in the EDI world to send/receive documents with different separators/delimiters being used. This can include the segment, element, and composite separators. The EDI profile cannot be set dynamically in the Trading Partner connector. If you are receiving multiple EDI documents like 850's, with the first one using a element delimiter *, and the second one using |, you may receive a generic parsing error. There are 2 possible solutions for this, a "Search/Replace" function in the Trading Partner or via a groovy script.


Solution 1: Search/Replace Function

You can have additional data processing in the Trading Partner (under the Communication Tab, select the Communication Method and a "Data Processing Option" will be present). 


From there search for the delimiter(s) you want to replace and choose what you want to replace with. 


Solution 2: Groovy Script

This method will not validate the incoming data. A 997 Acknowledgement will still be generated and it will always report as "Accepted"

  1. Go to your Trading Partner
  2. Go to the "Document Types" tab and click on your EDI document type
  3. Remove the Document Profile and save your shape
  4. Add Data Process shape after the Trading Partner

  5. Add the below script to the component. The following script will set the segment, element, and composite separators as the standard you defined for any incoming X12 documents. The last part of the script will then set the separator properties for the document
import java.util.Properties;
import groovy.transform.Field;

// Separator Options in the final output

// Modify Doc
def modifyDoc(ediDoc, props) {
     // Get separators
     String segmentSeparator = props.getProperty("connector.track.x12.interchange.endcharacter");
     String elementSeparator = props.getProperty("connector.track.x12.interchange.delimiter");
     String compositeSeparator = props.getProperty("connector.track.x12.interchange.compseparator");

     def replacement = {
          // Change segment separator
          if (it == segmentSeparator) {
          // Change element separator
          else if (it == elementSeparator) {
          // Change composite
          else if (it == compositeSeparator) {
          // Do not transform
          } else {
     return ediDoc.collectReplacements(replacement);

for( int i = 0; i < dataContext.getDataCount(); i++ ) {
     InputStream is = dataContext.getStream(i);
     Properties props = dataContext.getProperties(i);
     is = new ByteArrayInputStream(modifyDoc(is.getText("UTF-8"), props).getBytes("UTF-8"));
     // It's important to change the document properties after the characters change
     props.setProperty("connector.track.x12.interchange.endcharacter", STANDARD_SEGMENT_SEPARATOR);
     props.setProperty("connector.track.x12.interchange.delimiter", STANDARD_ELEMENT_SEPARATOR);
     props.setProperty("connector.track.x12.interchange.compseparator", STANDARD_COMPOSITE_SEPARATOR);
     dataContext.storeStream(is, props);


Special thanks to Steve Groff.