Visual Studio 2017 doesn't like 850 PO Example

Comments

11 comments

  • Avatar
    Jheminger

    Kind of what I am trying to accomplish:

    result.N1Loop = new List<Loop_N1_850>();

    foreach (var loopN1 in data["N1loop"])
    {
    var n1Loop = new Loop_N1_850();
    n1Loop.N1 = new N1();
    n1Loop.N1.EntityIdentifierCode_01 = loopN1["EIC"];
    n1Loop.N1.Name_02 = loopN1["Name"];
    n1Loop.N1.IdentificationCodeQualifier_03 = loopN1["ICQ"];
    n1Loop.N1.IdentificationCode_04 = loopN1["IC"];

    n1Loop.N2 = new N2();

    }
    0
    Comment actions Permalink
  • Avatar
    Admin

    Hi,

    You can familiarize yourself with C# lists here.

    Find example code for generating a sample purchase order here.

    .NET Tutorial here.

    Excerpt from the examples in the SDK (download from here);

    // Repeating N1 Loops 
    result.N1Loop = new List<Loop_N1_850>();

    // Begin N1 Loop
    var n1Loop = new Loop_N1_850();

    // Indicates that the buyer is ABC Aerospace. ABC's D-U-N-S+4 number is 123456789-0101.
    n1Loop.N1 = new N1();
    n1Loop.N1.EntityIdentifierCode_01 = "BY";
    n1Loop.N1.Name_02 = "ABC AEROSPACE";
    n1Loop.N1.IdentificationCodeQualifier_03 = "9";
    n1Loop.N1.IdentificationCode_04 = "1234567890101";

    // Repeating N2
    n1Loop.N2 = new List<N2>();

    // Provides additional name content for the buyer.
    var n2 = new N2();
    n2.Name_01 = "AIRCRAFT DIVISION";
    n1Loop.N2.Add(n2);

    // Repeating N3
    n1Loop.N3 = new List<N3>();

    // The buyer’s street address is 2000 Jet Blvd.
    var n3 = new N3();
    n3.AddressInformation_01 = "2000 JET BLVD";
    n1Loop.N3.Add(n3);

    // Repeating N4
    n1Loop.N4 = new List<N4>();

    // The buyer’s city, state, and ZIP is Fighter Town, CA 98898.
    var n4 = new N4();
    n4.CityName_01 = "FIGHTER TOWN";
    n4.StateorProvinceCode_02 = "CA";
    n4.PostalCode_03 = "98898";
    n1Loop.N4.Add(n4);

    // End N1 Loop
    result.N1Loop.Add(n1Loop);

    To iterate through the list:

    foreach(var loop in result.N1Loop)
    {
        var currentN1 = loop.N1;
        var currentN2 = loop.N2;

        // etc...
    }

    and regarding your snippet:

    result.N1Loop = new List<Loop_N1_850>();

    foreach (var loopN1 in result.N1Loop)
    {
        var n1Loop = new Loop_N1_850();
        n1Loop.N1 = new N1();
        n1Loop.N1.EntityIdentifierCode_01 = loopN1.N1.EntityIdentifierCode_01;
        // etc...
    }
    0
    Comment actions Permalink
  • Avatar
    Jheminger

    Thank you for your continued assistance.

    I need help again. Similar problem: I am getting an error when I add pidList to PIDLoop.

    This is as close as I am able to get after moving things around.

    pO1Loop.PIDLoop = new List<Loop_PID_850>();
    var pidList = new List<PID>();
    var pidLoop = new PID();
    pidLoop.ItemDescriptionType_01 = "";
    pidList.Add(pidLoop);
    pO1Loop.PIDLoop.Add(pidList);
    0
    Comment actions Permalink
  • Avatar
    Admin

    Hi,

    I believe I did post the link for generating a sample PO, here it is again, it shows how to create list of loops, lists of segments, etc.

    Here is a link to the EDI template for PO.

     

     

    0
    Comment actions Permalink
  • Avatar
    Jheminger

    Thank you That example doesn't cover multiple loops however.

    I am trying to extract data from a database for multiple PO's.

    The first row gathers the initial data then the PO's are added:

    static TS850 BuildEDI(string portID, string startDate, string endDate) {
    // In 99% of the cases this will be about 2kb
    // overall maybe 10 - 20 transactions
    //
    //

    getData(portID, startDate, endDate);

    var dtest = data;

    bool firstRow = true;

    var result = new TS850();
    result.PO1Loop = new List<Loop_PO1_850>();
    var PO1loop = new Loop_PO1_850();

    int iLength = 0;
    double dAmt = 0;
    foreach (var d in data)
    {
    if (firstRow == true)
    {
    var test = d;
    result.ST = new ST();
    result.ST.TransactionSetIdentifierCode_01 = "850";

    // ask if this is created at reuntime or pulled
    //result.ST.TransactionSetControlNumber_02 = d.Value["controlNumber"].PadLeft(9, '0');

    result.BEG = new BEG();
    result.BEG.TransactionSetPurposeCode_01 = "00";
    result.BEG.PurchaseOrderTypeCode_02 = "SA";
    result.BEG.PurchaseOrderNumber_03 = d.Value["POID"];
    //result.BEG.Date_05 = DateTime.TryParseExact("20181001","yyyyMMdd").ToString(); //DateTime.Now.ToString("yyyyMMdd");

    //result.BEG.ContractNumber_06 = d.Value["ContractNumber"];
    firstRow = false;

    result.N1Loop = new List<Loop_N1_850>();
    var n1Loop = new Loop_N1_850();
    n1Loop.N1 = new N1();
    n1Loop.N1.EntityIdentifierCode_01 = "ST";
    n1Loop.N1.Name_02 = d.Value["ShiptoName"]; // Verify
    n1Loop.N1.IdentificationCodeQualifier_03 = d.Value["ShiptoIDQ"];
    n1Loop.N1.IdentificationCode_04 = "123456789"; //d.Value["IC"]; // Ask
    /*
    n1Loop.N2 = new List<N2>();
    var n2 = new N2();
    n2.Name_01 =
    */
    n1Loop.N3 = new List<N3>();
    var n3 = new N3();
    n3.AddressInformation_01 = d.Value["ShiptoAddress"];
    n1Loop.N3.Add(n3);

    n1Loop.N4 = new List<N4>();
    var n4 = new N4();
    n4.CityName_01 = d.Value["ShiptoCity"];
    n4.StateorProvinceCode_02 = d.Value["ShiptoState"];
    n4.PostalCode_03 = d.Value["ShiptoZip"];
    n1Loop.N4.Add(n4);

    result.N1Loop.Add(n1Loop);


    } // End First Row Loop

    // Begin Looped Content
    // Indicates Baseline item 1 is a request to purchase 25 units, with a price of $36.00 each, of manufacturer's part number XYZ-1234.
    PO1loop.PO1 = new PO1();
    PO1loop.PO1.AssignedIdentification_01 = d.Value["ItemSQ"]; // Ask
    PO1loop.PO1.QuantityOrdered_02 = d.Value["ItemQty"];
    PO1loop.PO1.UnitorBasisforMeasurementCode_03 = d.Value["ItemUnit"];
    PO1loop.PO1.UnitPrice_04 = float.Parse(d.Value["ItemPrice"], CultureInfo.InvariantCulture).ToString();
    PO1loop.PO1.BasisofUnitPriceCode_05 = "PE"; // Ask
    PO1loop.PO1.ProductServiceIDQualifier_06 = d.Value["ItemIQ2"]; // Ask
    PO1loop.PO1.ProductServiceID_07 = d.Value["ItemID2"];
    result.PO1Loop.Add(PO1loop);
    /*
    * Need assistance from EDIFabric
    PO1loop.PIDLoop = new List<Loop_PID_850>();
    var pidList = new List<PID>();
    var pidLoop = new PID();
    pidLoop.ItemDescriptionType_01 = "";
    pidList.Add(pidLoop);
    PO1loop.PIDLoop.Add(pidList);
    */


    // Begin Incrementing Data
    iLength++;
    dAmt += (float.Parse(d.Value["ItemPrice"],CultureInfo.InvariantCulture) * int.Parse(d.Value["ItemQty"]));

    } // End data loop

    // Begin CTT Loop
    result.CTTLoop = new Loop_CTT_850();

    // Indicates that the purchase order contains 1 line item.
    result.CTTLoop.CTT = new CTT();
    result.CTTLoop.CTT.NumberofLineItems_01 = iLength.ToString();

    // Indicates that the total amount of the purchase order is $900.
    result.CTTLoop.AMT = new AMT();
    result.CTTLoop.AMT.AmountQualifierCode_01 = "";
    result.CTTLoop.AMT.MonetaryAmount_02 = Math.Round(dAmt,2).ToString();


    // End CT Loop

    return result;
    }

     

     

    0
    Comment actions Permalink
  • Avatar
    Jheminger

    I will have another look THX

    0
    Comment actions Permalink
  • Avatar
    Admin

    Hi,

    your 

    PO1loop.PIDLoop is List<Loop_PID_850>

    and 

    pidList is List<PID>

    hence PO1loop.PIDLoop can only add Loop_PID_850 and not PID

    0
    Comment actions Permalink
  • Avatar
    Jheminger

    Whew!!! Finally working.

    Getting the hang of this ( SORRY ) ... and, thanks for the patience.

    static TS850 BuildEDI(string portID, string startDate, string endDate) {
    // In 99% of the cases this will be about 2kb
    // overall maybe 10 - 20 transactions
    //
    //

    getData(portID, startDate, endDate);

    var dtest = data;

    bool firstRow = true;

    var result = new TS850();
    result.PO1Loop = new List<Loop_PO1_850>();
    var PO1loop = new Loop_PO1_850();



    int iLength = 0;
    double dAmt = 0;
    foreach (var d in data)
    {
    if (firstRow == true)
    {
    var test = d;
    result.ST = new ST();
    result.ST.TransactionSetIdentifierCode_01 = "850";

    // ask if this is created at reuntime or pulled
    //result.ST.TransactionSetControlNumber_02 = d.Value["controlNumber"].PadLeft(9, '0');

    result.BEG = new BEG();
    result.BEG.TransactionSetPurposeCode_01 = "00";
    result.BEG.PurchaseOrderTypeCode_02 = "SA";
    result.BEG.PurchaseOrderNumber_03 = d.Value["POID"];
    //result.BEG.Date_05 = DateTime.TryParseExact("20181001","yyyyMMdd").ToString(); //DateTime.Now.ToString("yyyyMMdd");

    //result.BEG.ContractNumber_06 = d.Value["ContractNumber"];
    firstRow = false;

    result.N1Loop = new List<Loop_N1_850>();
    var n1Loop = new Loop_N1_850();
    n1Loop.N1 = new N1();
    n1Loop.N1.EntityIdentifierCode_01 = "ST";
    n1Loop.N1.Name_02 = d.Value["ShiptoName"]; // Verify
    n1Loop.N1.IdentificationCodeQualifier_03 = d.Value["ShiptoIDQ"];
    n1Loop.N1.IdentificationCode_04 = "123456789"; //d.Value["IC"]; // Ask
    /*
    n1Loop.N2 = new List<N2>();
    var n2 = new N2();
    n2.Name_01 =
    */
    n1Loop.N3 = new List<N3>();
    var n3 = new N3();
    n3.AddressInformation_01 = d.Value["ShiptoAddress"];
    n1Loop.N3.Add(n3);

    n1Loop.N4 = new List<N4>();
    var n4 = new N4();
    n4.CityName_01 = d.Value["ShiptoCity"];
    n4.StateorProvinceCode_02 = d.Value["ShiptoState"];
    n4.PostalCode_03 = d.Value["ShiptoZip"];
    n1Loop.N4.Add(n4);

    result.N1Loop.Add(n1Loop);


    } // End First Row Loop

    // Begin Looped Content
    // Indicates Baseline item 1 is a request to purchase 25 units, with a price of $36.00 each, of manufacturer's part number XYZ-1234.
    PO1loop.PO1 = new PO1();
    PO1loop.PO1.AssignedIdentification_01 = d.Value["ItemSQ"]; // Ask
    PO1loop.PO1.QuantityOrdered_02 = d.Value["ItemQty"];
    PO1loop.PO1.UnitorBasisforMeasurementCode_03 = d.Value["ItemUnit"];
    PO1loop.PO1.UnitPrice_04 = float.Parse(d.Value["ItemPrice"], CultureInfo.InvariantCulture).ToString();
    PO1loop.PO1.BasisofUnitPriceCode_05 = "PE"; // Ask
    PO1loop.PO1.ProductServiceIDQualifier_06 = d.Value["ItemIQ2"]; // Ask
    PO1loop.PO1.ProductServiceID_07 = d.Value["ItemID2"];

    // Followed the template
    // This will get easier te more I read them
    PO1loop.PIDLoop = new List<Loop_PID_850>();
    var loopPID = new Loop_PID_850();
    loopPID.PID = new PID();
    loopPID.PID.ItemDescriptionType_01 = ""; // ironically enough after all this there is no data fields that correspond
    loopPID.PID.Description_05 = ""; // But it helps me learn
    PO1loop.PIDLoop.Add(loopPID);


    // Moved the ADD PO1loop HERE
    result.PO1Loop.Add(PO1loop);

    // Begin Incrementing Data
    iLength++;
    dAmt += (float.Parse(d.Value["ItemPrice"],CultureInfo.InvariantCulture) * int.Parse(d.Value["ItemQty"]));

    } // End data loop

    // Begin CTT Loop
    result.CTTLoop = new Loop_CTT_850();

    // Indicates that the purchase order contains 1 line item.
    result.CTTLoop.CTT = new CTT();
    result.CTTLoop.CTT.NumberofLineItems_01 = iLength.ToString();

    // Indicates that the total amount of the purchase order is $900.
    result.CTTLoop.AMT = new AMT();
    result.CTTLoop.AMT.AmountQualifierCode_01 = "";
    result.CTTLoop.AMT.MonetaryAmount_02 = Math.Round(dAmt,2).ToString();


    // End CT Loop

    return result;
    }

     

    0
    Comment actions Permalink
  • Avatar
    Admin

    No problem at all, I'm glad you're getting your head around it. Once you do one template, you've done them all.

    BTW, I have a hunch that you come from a different programming language, that is not C#, I hope you don't mind me asking what is it ? I'd be curious to know your honest opinion about how did you find the clarity of the documentation and source code examples to get you started and if there was anything else that would've helped to make this transition easier for you.   

    0
    Comment actions Permalink
  • Avatar
    Jheminger

    It's that obvious, ehe? LOL. I mostly write in Javascript or PHP and a little Python. I took a C# course over a year ago. But, that's all the experience I had in it until now.

    I tend to learn by doing. Reworking examples I find. So, the more samples, the better.

    Maybe just a little explanation of what templates are and how the hierarchy works. ( this likely exists ).

    All in all the experience has been very positive. Good documentation, examples and great support.

    My employers seem happy with my results. Since we will no longer be reinventing the wheel so much when we need a new EDI this, in theory, should save us a lot of time.

    My current implementation is here if your curious:

    https://github.com/061375/EDIFabric-Implementation-Test

    Since most of the EDI will be the X12850 I built a main class around that and it sub-classes when there are differences in the customer variables.

     

     

    0
    Comment actions Permalink
  • Avatar
    Admin

    Thank you for taking the time and giving an honest answer. Publishing a link to your implementation is very much appreciated and I'm sure others will benefit from it.

    Cheers,

    Don

    0
    Comment actions Permalink

Please sign in to leave a comment.