Scripting for EDI - Multiple Insert Afters sample

Introduction

The script below is an example of how to perform multiple "Insert Afters" in a row.  Each function can only insert one segment.  Therefore the functions must be chained together to insert multiple segments.


' Script to do insert multiple segments in a sequence

Function XXX()   ' Replace XXX with the segment you need to insert the segments after
  '  Setup to call the function "Insert_N1" to insert the N1 segment
  EDI.InsertAfterFunction = "Insert_N1"  ' Tell the system to call 'Insert_N1' instead of the default 'InsertAfter' function
  EDI.InsertAfter = True
End Function

Function Insert_N1()
  EDI.InsertSegment = "N1"
  EDI.Element(1) = "ST"
  EDI.Element(2) = "Customer Name"
  EDI.Element(3) = "Location Qualifier"
  EDI.Element(4) = "Location Code"

  ' After inserting the N1 segment, the following tells the system to insert another segment
  ' using the function "Insert_N3"
  
  EDI.InsertAfterFunction = "Insert_N3"  
  EDI.InsertAfter = True
End Function

Function Insert_N3()
  EDI.InsertSegment = "N3"
  EDI.Element(1) = "Address Line 1"
  EDI.Element(2) = "Address line 2"

  ' After inserting the N3 segment, the following tells the system to insert another segment
  ' using the function "Insert_N4"
  
  EDI.InsertAfterFunction = "Insert_N4"  
  EDI.InsertAfter = True
End Function

Function Insert_N4()
  EDI.InsertSegment ="N4"
  EDI.Element(1) = "City"
  EDI.Element(2) = "State"
  EDI.Element(3) = "Postal Code"
  EDI.Element(4) = "Country Code"
End Function