You can validate EDI objects for compliance by invoking IsValid for every IEdiItem. When IsValid returns False then the EDI object is invalid and the MessageErrorContext object gets populated with information about the issues.
Message Error Context
The MessageErrorContext contains the following details:
- The transaction type, version and control number of the validated object
- The Codes collection containing any structural message level errors
- The HasErrors property, which checks if either the Codes or the Errors have any items
- The Errors collection containing all segment specific issues (SegmentErrorContext) Should at least an item exists in this collection, MessageErrorCode.MessageWithErrors is added to the Codes collection
Segment Error Context
The SegmentErrorContext is a container for all the issues found in a segment and has the following identification properties;
- Name, this is the segment tag, e.g. BIG or DTM
- Value, this is the actual value of the segment from the original EDI document
- SpecType, this holds the type of the segment in the EDI template
- Position, this is the position of the segment within its transaction, starting from ST or UNH which are at position 0
These properties should be sufficient to identify the whereabouts of any invalid segment in the original EDI document and to point to the corresponding class in the EDI template.
A SegmentErrorContext can contain multiple validation issues, for multiple data elements with errors for example. All the issues are listed under:
- The Codes collection containing the segment specific error codes
- The Errors collection containing all data element specific issues (DataElementErrorContext)
DataElement Error Context
The DataElementErrorContext is a container for all the issues found for a particular data element and has the following identification properties:
- Name, this is either the code defined the complex data element:
or the code defined for the simple data element:
- Value, this is the actual value of the data element from the original EDI document
- Position, this is the position of the complex or simple data element within the segment
- ComponentPosition, this is the position of the simple data element within the complex element. If the data element is part of a segment only, this is 0.
- RepetitionPosition, this is the position of the composite or simple repeating data element within the List
These properties should be sufficient to identify the data elements that are invalid.
The architecture of the error contexts allows EdiFabric's AckMan to generate fully compliant EDI acknowledgments with the correct error codes.
User Friendly Error Messages
The MessageErrorContext provides a Flatten method that lists all the errors in a single table, such as:
[BGM at pos 3] [4345 at pos 6 with value 123456789ABC] DataElementTooLong
Custom error messages are possible by creating custom attributes (inherited from any of the validation attributes) or applying custom validation.