indice-co / indice-co/EDI.Net

Mapping repeated elements in a segment

Open
#233 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
490
Forks
173
PR merge metrics
No merged PRs in 30d

Description

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*a_customer@example.com~
```

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
```csharp
// 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 { 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: a_customer@example.com
}
]
}
```

while I'd like to get

```
Contact: {
ContactFunctionCode: OC,
Name: Customer ABC,
CommunicationData: [
{
Qualifier: TE,
Value: 1234123412
},
{
Qualifier: EM
Value: a_customer@example.com
}
]
}
```

Is there anything obvious I'm missing here?

**Library version:** `1.11.0`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the EdiValue paths on AdministrativeCommunicationsContact and CommunicationData, and compare them with the PER segment shown in the issue. Investigate how repeated PER elements are mapped into CommunicationData; done means each qualifier is paired with the following value as two objects, matching the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.