BOI PO_PurchaseOrder creation.

SOLVED

Background: We're using the C# NuGet package.

When I have a session object (Sage100.ObjectManagement.MasSession), I'm able to do the following (though, actual creation inevitably fails because of needed line items).

var createObject = session.CreateObject<IMasBusinessObject>("PO_PurchaseOrder_bus", "PO_PurchaseOrder_ui", "P/O");
// SKIP VERBOSITY.
.......
createObject.Write();

----------------------------------------------

However, when attempting to do the following, the CreateObject fails immediately saying that the PO_PurchaseOrder_bus object does not exist. Exact error: KeyNotFoundException: The given key 'PO_PurchaseOrder_Bus' was not present in the dictionary.

var createObject = session.CreateObject<ILineEntry>("PO_PurchaseOrder_bus", "PO_PurchaseOrder_ui", "P/O");

----------------------------------------------

Any ideas? After looking at the documentation (and through just plain investigation), you can't create the PO_PurchaseOrderHeader record because you need line items... thus, the ILineEntry noted in the failing line above.

The above methodology that doesn't work on PO_PurchaseOrder_bus works just fine for invoices (which should follow a similar methodology, AR_Invoice_Bus).

  • +1
    verified answer

    Josh,
    The issue is due to "PO_PURCHASEORDER_BUS" not being defined in the collection of line entry types. This can be handled at runtime though, using the following line of code.


    CI.ColumnNames.Add("PO_PURCHASEORDER_BUS", new Dictionary<string, string> { { CI.NextNumberMethod, "nGetNextPurchaseOrderNo" }, { CI.HeaderKeyColumns, "PurchaseOrderNo$" } });


    And a full usage example based on ABC demo data.

        class Program
        {
            private static readonly SessionLogon _logon = new SessionLogon
            {
                CompanyCode = "ABC",
                UserLogon = new NetworkCredential { UserName = "all", Password = "" },
                ModuleCode = "P/O",
                ModuleDate = DateTime.Today
            };
    
            static void Main(string[] args)
            {
                using (IMasSession session = new MasSession())
                {
                    try
                    {
                        session.InitSession(_logon);
    
                        CI.ColumnNames.Add("PO_PURCHASEORDER_BUS", new Dictionary<string, string> { { CI.NextNumberMethod, "nGetNextPurchaseOrderNo" }, { CI.HeaderKeyColumns, "PurchaseOrderNo$" } });
    
                        using (var po = session.CreateObject<ILineEntry>("PO_PurchaseOrder_bus", "PO_PurchaseOrder_ui", "P/O"))
                        {
                            var nextOrderNo = po.GetNextDocumentNumber();
    
                            po.SetKey(nextOrderNo);
                            po.SetValue("APDivisionNo", "01");
                            po.SetValue("VendorNo", "AIRWAY");
    
                            po.AddLine();
                            
                            Trace.WriteLine(po.Lines.GetKey());
    
                            po.Lines.SetValue("ItemCode", "1001-HON-H252");
                            po.Lines.SetValue("QuantityOrdered", 2);
                            
                            po.Lines.Write();
                            po.Write();
                        }
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception.Message);
                    }
                }
            }
        }

    Hope this helps,

    Russell