2014-10-08 118 views
0

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

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(); 
      } 
} 

感谢您的帮助。

+0

您是否收到任何错误?或者它什么都不做? – Gabriel 2014-10-08 17:09:12

+0

不是。但是数据无法插入到数据库中 – 2014-10-09 00:59:02

+0

我可以发现这个代码的一些问题,但它在4.2中正常工作并且插入了一个订单。首先,你应该用DateTime.Today替换DateTime.Now。 – Gabriel 2014-10-09 02:00:28

回答

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(); 
+0

我试过但仍然没有任何反应。当我调试时,我发现OrderNbr为新订单,但在此之后,没有任何内容插入到数据库中。 – 2014-10-09 06:46:24

+0

您是否有销售订单的自定义功能? – Ken 2014-10-09 08:23:51

+0

是的,我在销售订单屏幕上通过为SOLine – 2014-10-09 08:35:50

0

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

+0

这是如何解决问题的?另外请注意Actions.PressSave()是推荐的方式来保存,而不是Psrsist() – Gabriel 2014-10-18 00:51:18

+0

我同意PressSave是更好的选择。但是,似乎OP在这种方法上遇到了一些困难。在处理CRM案例活动时,我遇到了类似的问题。我被迫打电话给Persist方法。然后在活动主视图上调用Refresh,以便我可以看到已保存的新活动。 – 2014-10-22 16:44:20

相关问题