Get PurchaseOrder and Lineitems

SOLVED

How to get PurchaseOrderNo using PurchaseOrder Details & LineItems data from Sage 100 desktop application using C#?

I have using DispatchObject and done login and select company functionality.

Can you please help me to get PO detail using C#?

Parents
  • +1
    verified answer

    You may want to try searching for examples on here. Most scripting for sage 100 is done in VBScript but there are a few examples for other languages.

    I found this post which should give you the bulk of what needs done.

    https://www.sagecity.com/support_communities/sage100_erp/f/sage-100-business-object-interface/90544/c-po-write-fails-boi/297653#297653

    Since you want the line item data, you can't use the PO_PurchaseOrder_Svc class, instead, you will have to use PO_PurchaseOrder_Bus so you can access the oLines property which is the object handle to the PO_PurchaseOrderDetail_Bus class which will allow you to loop through the lines in a similar fashion to looping through an ADO recordset.

    When you use nSetKey on the header (PO_PurchaseOrder_Bus), it should filter the detail (PO_PurchaseOrderDetail_Bus) to only loop through the respective purchase order line's vs every line in the table.

    Alternatively, you can query the data via ODBC and loop through the resulting recordset. You would query data either individually from PO_PurchaseOrderHeader and PO_PurchaseOrderDetail or if you are going to join the tables into one query, use an INNER JOIN on the PurchaseOrderNo field.

  • 0 in reply to David Speck

               using (DispatchObject poObject = new DispatchObject(pvx.InvokeMethod("NewObject", "PO_PurchaseOrder_bus", oSS.GetObject())))
                {
    
                    poObject.InvokeMethod("nMoveFirst");
                    int sEOF = (int)poObject.GetProperty("nEOF");
                    do
                    {
                        var purchaseOrder = new PurchaseOrder();
                        purchaseOrder.PurchaseOrderNo = poObject.GetDataObject("PurchaseOrderNo$");
                        purchaseOrder.OrderDate = TextUtilities.ConvertDate(poObject.GetDataObject("PurchaseOrderDate$"));
    
                        using (DispatchObject po_line = new DispatchObject(poObject.GetProperty("oLines")))
                        {
                            po_line.InvokeMethod("nMoveFirst");
                            int EOF = (int)po_line.GetProperty("nEOF");
                            do
                            {
                                   var item = new LineItem
                                    {
                                        ItemCode = po_line.GetDataObject("ItemCode$"),
                                        Description = po_line.GetDataObject("ItemCodeDesc$"),
                                        UPC = po_line.GetDataObject("UnitOfMeasure$"),
                                        MFGCode = po_line.GetDataObject("PurchasesAcctKey$"),
                                        Quantity = TextUtilities.ConvertInt(po_line.GetDataObject("QuantityOrdered$")),
                                        QuantityShipped = TextUtilities.ConvertInt(po_line.GetDataObject("QuantityReceived$"))
                                    };
    
                                    purchaseOrder.AddLine(item);
    
                                po_line.InvokeMethod("nMoveNext");
                                EOF = (int)po_line.GetProperty("nEOF");
    
                            } while (EOF != 1);
                        }
    
                        purchaseOrderList.Add(purchaseOrder);
    
                        poObject.InvokeMethod("nMoveNext");
                        sEOF = (int)poObject.GetProperty("nEOF");
    
                    } while (sEOF != 1);
                }
    
    
    


    I have got the purchase order and line items data.


    And I have used the keyword "QuantityOrdered" to get the quantity data and unit price. But I didn't get it.

    I need to get item full data (see below image).

    Can you please help me?


Reply
  • 0 in reply to David Speck

               using (DispatchObject poObject = new DispatchObject(pvx.InvokeMethod("NewObject", "PO_PurchaseOrder_bus", oSS.GetObject())))
                {
    
                    poObject.InvokeMethod("nMoveFirst");
                    int sEOF = (int)poObject.GetProperty("nEOF");
                    do
                    {
                        var purchaseOrder = new PurchaseOrder();
                        purchaseOrder.PurchaseOrderNo = poObject.GetDataObject("PurchaseOrderNo$");
                        purchaseOrder.OrderDate = TextUtilities.ConvertDate(poObject.GetDataObject("PurchaseOrderDate$"));
    
                        using (DispatchObject po_line = new DispatchObject(poObject.GetProperty("oLines")))
                        {
                            po_line.InvokeMethod("nMoveFirst");
                            int EOF = (int)po_line.GetProperty("nEOF");
                            do
                            {
                                   var item = new LineItem
                                    {
                                        ItemCode = po_line.GetDataObject("ItemCode$"),
                                        Description = po_line.GetDataObject("ItemCodeDesc$"),
                                        UPC = po_line.GetDataObject("UnitOfMeasure$"),
                                        MFGCode = po_line.GetDataObject("PurchasesAcctKey$"),
                                        Quantity = TextUtilities.ConvertInt(po_line.GetDataObject("QuantityOrdered$")),
                                        QuantityShipped = TextUtilities.ConvertInt(po_line.GetDataObject("QuantityReceived$"))
                                    };
    
                                    purchaseOrder.AddLine(item);
    
                                po_line.InvokeMethod("nMoveNext");
                                EOF = (int)po_line.GetProperty("nEOF");
    
                            } while (EOF != 1);
                        }
    
                        purchaseOrderList.Add(purchaseOrder);
    
                        poObject.InvokeMethod("nMoveNext");
                        sEOF = (int)poObject.GetProperty("nEOF");
    
                    } while (sEOF != 1);
                }
    
    
    


    I have got the purchase order and line items data.


    And I have used the keyword "QuantityOrdered" to get the quantity data and unit price. But I didn't get it.

    I need to get item full data (see below image).

    Can you please help me?


Children