【问题标题】:Create sales order via code 2017 R2通过代码 2017 R2 创建销售订单
【发布时间】:2018-01-17 07:33:26
【问题描述】:

我正在尝试使用从我的 edi 系统检索到的数据创建销售订单。我有用于检索订单的代码,但在创建 SO 时遇到问题。我可以使用 SOAP 接口通过外部程序创建它们,但我正在尝试使用图形并直接插入它们。我收到一个异常说明“{”错误:处理字段 CustomerLocationID 期间发生错误:对象引用未设置为对象的实例..“}”但我成功查找了客户 ID 和位置 ID。这是我的例程的代码。我使用类似的代码为我创建的一组新的主/明细表创建记录。

请告知是否有人对以这种方式创建销售订单有见解。错误被抛出: soOrder.CurrentDocument.Insert(order);

我在尝试访问 SOOrder 和 SOLine 的扩展字段时也遇到了错误。我目前已将这些字段注释掉以查看是否可以创建订单,但我还需要在其中加载数据。

        foreach (LingoOrderSearch ediOrder in doc850)
        {
            res850 = lingo.Retrieve850(ediOrder.documentId, "850");
            SOOrderEntry soOrder = PXGraph.CreateInstance<SOOrderEntry>();
            soOrder.Clear();
            var order = new SOOrder();
            //SOOrderExt orderExt = order.GetExtension<SOOrderExt>();

            order.OrderType = "SO";
            order.Status = "Open";
            if (res850.Data850.partner == "BEDBATH" || res850.Data850.partner == "BEDBATH_CAN")
                customerLookup = "BBB";
            else
                customerLookup = res850.Data850.partner;
            CustomerMaint customerGraph = PXGraph.CreateInstance<CustomerMaint>();
            Customer arCustomer = PXSelect<Customer, Where<Customer.status, Equal<Required<Customer.status>>,
                And<Customer.acctCD, Equal<Required<Customer.acctCD>>>>>.Select(this, "Active", customerLookup);
            if (arCustomer == null)
                throw new PXException("Unable to find customer " + customerLookup + " (partner:" + res850.Data850.partner + ")");
            order.CustomerID = arCustomer.BAccountID;
            CustomerLocationMaint customerLocationGraph = PXGraph.CreateInstance<CustomerLocationMaint>();
            Location arCustomerLocation = PXSelect<Location, Where<Location.isActive, Equal<Required<Location.isActive>>,
                And<Location.bAccountID, Equal<Required<Location.bAccountID>>,
                And<Location.locationCD, Equal<Required<Location.locationCD>>>>>>
                .Select(this, true, arCustomer.BAccountID, res850.Data850.location);
            if (arCustomerLocation == null)
                throw new PXException("Unable to find customer location" + customerLookup + " / " +
                    res850.Data850.location  + " (partner:" + res850.Data850.partner + ")");
            order.CustomerLocationID = arCustomerLocation.LocationID;
            order.CustomerOrderNbr = res850.Data850.poNumber;
            order.ExtRefNbr = res850.Data850.documentId.ToString();
            //orderExt.UsrEDICustomerVendorId = res850.Data850.vendor;
            //orderExt.UsrEDICustomerId = res850.Data850.partner;
            if (!DateTime.TryParse(res850.Data850.poDate, out tempDate))
            {
                tempDate = DateTime.Today;
            }
            order.DocDate = tempDate;                
            DateTime.TryParse(res850.Data850.requestedDeliveryDate, out tempDate);
            if (!DateTime.TryParse(res850.Data850.requestedDeliveryDate, out tempDate))
            {
                tempDate = DateTime.Today;
            }
            order.RequestDate = tempDate;
            soOrder.CurrentDocument.Insert(order);
            soOrder.Persist();
            newOrderId = soOrder.CurrentDocument.Current.OrderNbr;

            itemList = res850.Data850.items;
            foreach (EdiDoc850Lingoitems item in itemList)
            {
                InventoryItemMaint invItemGraph = PXGraph.CreateInstance<InventoryItemMaint>();
                InventoryItem invItem = PXSelect<InventoryItem, 
                    Where<InventoryItem.itemStatus, Equal<Required<InventoryItem.itemStatus>>,
                    And<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>>
                    .Select(this, "Active", item.vendorItem);
                if (invItem == null)
                    throw new PXException("Unable to locate item " + item.vendorItem);
                var line = new SOLine();
                //SOLineExt lineExt = line.GetExtension<SOLineExt>();
                line.OrderNbr = newOrderId;
                line.InventoryID = invItem.InventoryID;
                line.Qty = item.qtyOrder;
                line.ShipComplete = "Ship Complete";
                Int32 tempLine = 0;
                if (Int32.TryParse(item.lineNo, out tempLine)) { };
                //lineExt.UsrEDILineNbr = tempLine;
                soOrder.Transactions.Insert(line);
            }
        }
    }

【问题讨论】:

    标签: acumatica


    【解决方案1】:

    希望下面的示例将有助于您完成任务:

    SOOrderEntry soOrder = PXGraph.CreateInstance<SOOrderEntry>();
    var order = new SOOrder();
    order.OrderType = SOOrderTypeConstants.SalesOrder;
    order = soOrder.CurrentDocument.Insert(order);
    
    Customer arCustomer = PXSelect<Customer, Where<Customer.status, Equal<Required<Customer.status>>,
        And<Customer.acctCD, Equal<Required<Customer.acctCD>>>>>.Select(this, "Active", "ABARTENDE");
    if (arCustomer == null)
        throw new PXException("Unable to find customer");
    order.CustomerID = arCustomer.BAccountID;
    order = soOrder.CurrentDocument.Update(order);
    
    Location arCustomerLocation = PXSelect<Location, Where<Location.isActive, Equal<Required<Location.isActive>>,
        And<Location.bAccountID, Equal<Required<Location.bAccountID>>,
        And<Location.locationCD, Equal<Required<Location.locationCD>>>>>>
        .Select(this, true, arCustomer.BAccountID, "CHICAGO");
    if (arCustomerLocation == null)
        throw new PXException("Unable to find customer location");
    order.CustomerLocationID = arCustomerLocation.LocationID;
    order.CustomerOrderNbr = "res850.Data850.poNumber";
    order.ExtRefNbr = "res850.Data850.documentId";
    order.RequestDate = DateTime.Today;
    soOrder.CurrentDocument.Update(order);
    
    for(int i = 0; i < 3; i++)
    {
        InventoryItem invItem = PXSelect<InventoryItem,
            Where<InventoryItem.itemStatus, Equal<Required<InventoryItem.itemStatus>>,
            And<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>>
            .Select(this, "Active", "AALEGO500");
        if (invItem == null)
            throw new PXException("Unable to locate item");
        var line = soOrder.Transactions.Insert();
        line.InventoryID = invItem.InventoryID;
        line.Qty = 1;
        line.ShipComplete = SOShipComplete.ShipComplete;
        soOrder.Transactions.Update(line);
    }
    
    soOrder.Actions.PressSave();
    

    【讨论】:

    • 感谢鲁斯兰的快速回复。仅供参考,是什么让销售订单与我创建的自定义对象不同?我应该总是先插入一条空记录,然后一次更新一个键值吗?这是一个框架的东西还是只是与如何定义销售订单有关的东西?我只是想了解这一点以备将来定制。
    • 嗨,Jerry,经验法则实际上是在向缓存中插入新记录之前为所有关键字段分配值。唯一的例外是当您在 DAC(读取、字段属性)或 BLC 级别上具有 FieldDefaulting 或 RowInserting 事件处理程序时,这将确保在将记录插入缓存之前生成并为关键字段分配值。
    猜你喜欢
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多