在Acumatica中按图形插入销售订单

时间:2014-10-08 15:54:20

标签: cloud erp acumatica

我正在尝试通过图表插入销售订单 我的代码是有效的,但无法插入数据库 这是我创建销售订单的代码。我正在使用Acumatica 4.0

void genSO(string outletCD,string salesmanCD)
{
            Customer cus =
                PXSelect<Customer, Where<Customer.acctCD, Equal<Required<Customer.acctCD>>>>
                    .Select(this, outletCD);

            SalesPerson salesman=
                PXSelect<SalesPerson, Where<SalesPerson.salesPersonCD, Equal<Required<SalesPerson.salesPersonCD>>>>
                    .Select(this, salesmanCD);


            if (cus != null && cus.BAccountID != null )
            {

                SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();
                SOOrder newOrder = graph.Document.Insert();
                newOrder.OrderType = "SO";
                newOrder.OrderDate=DateTime.Now;
                newOrder.RequestDate = DateTime.Now;
                newOrder.CustomerID = cus.BAccountID;

                graph.Document.Cache.RaiseFieldUpdated<SOOrder.customerID>(newOrder, null);
                newOrder.SalesPersonID = smNPP.SalesPersonID;
                graph.Document.Cache.RaiseFieldUpdated<SOOrder.salesPersonID>(newOrder, null);


                newOrder.Status = "N";
                graph.Document.Current = newOrder;

                graph.Document.Cache.Update(newOrder);
                graph.Actions.PressSave();
            }
}

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

试试这个:

SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();
SOOrder newOrder = (SOOrder)graph.Document.Cache.CreateInstance();
//Fill only keys.
newOrder.OrderType = "SO";    
newOrder = sograph.Document.Insert(newOrder);
//Apply automation step.
newOrder = PXCache<SOOrder>.CreateCopy(graph.Document.Search<SOOrder.orderNbr>(newOrder.OrderNbr));
newOrder.OrderDate=DateTime.Now;
newOrder.RequestDate = DateTime.Now;
newOrder.CustomerID = cus.BAccountID;
newOrder.SalesPersonID = smNPP.SalesPersonID;
graph.Document.Update(newOrder);
graph.Actions.PressSave();

答案 1 :(得分:0)

graph.Document.Insert(newOrder); graph.Persist();