EDI.Net
EDI.Net copied to clipboard
Mapping repeated elements in a segment
First of all, thanks for your work and support of the library!
I saw #105 and #121 , which were the basis for the mapping. That being said, I still seem to be missing something.
We're working with X12 850 Purchase Order message, and here's the relevant excerpt
N1*ST*Customer ABC~
N2*Suite 1123~
N3*11111 S. Main Ave.~
N4*New York*NY*10001*USA~
PER*OC*Customer ABC*TE*1234123412*EM*[email protected]~
The focus here is the PER segment, where we have the code, name, then the qualifier and the 'number'.
Now, apart from the TE (telephone) number, we also have an EM email, so that's potentially a repeated element.
Let's try mapping it appropriately
// Majority of this definition is taken from the test sample data mapping for X12 850
[EdiSegment]
[EdiSegmentGroup("N1", SequenceEnd = "PO1")]
public class Address
{
[EdiValue(Path = "N1/0", Description = "N101 - Address Code")]
public string? AddressCode { get; set; }
[EdiValue(Path = "N1/1", Description = "N102 - Address Name")]
public string? AddressName { get; set; }
[EdiValue(Path = "N3/0", Description = "N301 - Address Information")]
public string? AddressInformation { get; set; }
[EdiValue(Path = "N4/0", Description = "N401 - City Name")]
public string? CityName { get; set; }
[EdiValue(Path = "N4/3", Description = "N404 - Country Code")]
public string? CountryCode { get; set; }
// ------------- up to here
// Here's a new property
public AdministrativeCommunicationsContact Contact { get; set; }
}
[EdiSegment]
[EdiPath("PER")]
public class AdministrativeCommunicationsContact
{
[EdiValue("X(2)", Path = "PER/0")]
public string ContactFunctionCode { get; set; }
[EdiValue(Path = "PER/1")]
public string? Name { get; set; }
[EdiValue(Path = "PER/2..*")]
public List<CommunicationData> CommunicationData { get; set; }
}
[EdiElement]
public class CommunicationData
{
[EdiValue("X(2)", Path="*/*/0")]
public string Qualifier { get; set; }
[EdiValue(Path="*/*/1")]
public string Value { get; set; }
}
This is the closest I got to having it work, but it's still not right:
Contact: {
ContactFunctionCode: OC,
Name: Customer ABC,
CommunicationData: [
{
Qualifier: TE
},
{
Qualifier: 1234123412
},
{
Qualifier: EM
},
{
Qualifier: [email protected]
}
]
}
while I'd like to get
Contact: {
ContactFunctionCode: OC,
Name: Customer ABC,
CommunicationData: [
{
Qualifier: TE,
Value: 1234123412
},
{
Qualifier: EM
Value: [email protected]
}
]
}
Is there anything obvious I'm missing here?
Library version: 1.11.0
@pcwiek Did you figure out the why value is not being populated?
Unfortunately not @jhedfactolerin
I didn't have the chance to spend more time on it though. Ultimately I ended up post-processing the 'incorrectly' tokenized data into a more suitable shape.
Thanks @pcwiek. I currently facing the same issue. I think it is not possible with the way it is right now.