Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping repeated elements in a segment #233

Open
pcwiek opened this issue Oct 14, 2022 · 3 comments
Open

Mapping repeated elements in a segment #233

pcwiek opened this issue Oct 14, 2022 · 3 comments

Comments

@pcwiek
Copy link

pcwiek commented Oct 14, 2022

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

@jhedfactolerin
Copy link

@pcwiek Did you figure out the why value is not being populated?

@pcwiek
Copy link
Author

pcwiek commented Feb 27, 2023

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.

@jhedfactolerin
Copy link

jhedfactolerin commented Feb 27, 2023

Thanks @pcwiek. I currently facing the same issue. I think it is not possible with the way it is right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants