2017-07-26 55 views
0

我试图使用SOOrderEntry图形对象从PO屏幕创建销售订单。我选择使用从另一个堆栈溢出的情况下的技术分支,和我不断收到以下错误:使用图形对象创建销售订单时出错

enter image description here

我想不通为什么这个错误就要到了,因为我设置客户ID。下面的代码:

public class POOrderEntryExt : PXGraphExtension<POOrderEntry> 
{ 
    public override void Initialize() 
    { 
     Base.action.AddMenuAction(CreateSO); 
    } 

    public PXAction<POOrder> CreateSO; 
    [PXUIField(DisplayName = "Create Sales Order", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)] 
    [PXButton] 
    protected virtual void createSO() 
    { 


     SOOrderEntry sograph = null; 
     SOOrder soorder = null; 
     SOLine soline = null; 

     //Let's get the current data from the screen we're in... 
     var poorder = (POOrder)Base.Document.Current; 
     PXResultset<POLine> res = PXSelect<POLine, Where<POLine.orderNbr, Equal<Required<POLine.orderNbr>>>>.Select(Base, poorder.OrderNbr); 

     using (PXLoginScope ls = new PXLoginScope("admin")) 
     { 

      //Create a new instance of the AP Bills screen graph.. 
      sograph = PXGraph.CreateInstance<SOOrderEntry>(); 

      //Get the branch... 
      var branch = (Branch)PXSelect<Branch, Where<Branch.branchCD, Equal<Required<Branch.branchCD>>>>.Select(Base, "WI-NVC VET"); 
      //soorder.BranchID = branch.BranchID; 

      //This handler is added per RD from another Stack Overflow case. It's necessary to select the Branch... 
      sograph.FieldDefaulting.AddHandler<SOOrder.branchID>((s, e) => 
      { 
       e.NewValue = branch.BranchID; 
       e.Cancel = true; 
      }); 


      soorder = new SOOrder(); 

      //The OrderType... 
      soorder.OrderType = SOOrderTypeConstants.SalesOrder; 
      sograph.Document.Insert(soorder); 

      soorder.OrderDate = (DateTime?)DateTime.Now; 
      soorder.RequestDate = (DateTime?)DateTime.Now; 



      //Get the customer id... 
      var bacct = (BAccountR)PXSelect<BAccountR, Where<BAccountR.acctCD, Equal<Required<BAccountR.acctCD>>>>.Select(Base, "NE-C003118"); 
      soorder.CustomerID = bacct.BAccountID; // (int?)5454; 

      sograph.Document.Update(soorder); 
      sograph.Actions.PressSave(); 

回答

1

这是很进口PXCache插入或更新方法调用的结果总是分配给当地一些变量,以便进一步您从缓存中进行更改的对象,而不是一个传统的记录,与PXCache没有任何共同之处。很多感谢 -

soorder = new SOOrder(); 
soorder.OrderType = SOOrderTypeConstants.SalesOrder; 
soorder = sograph.Document.Insert(soorder); 
+0

也做到了,鲁斯兰:

的问题应该由以下的微小变化来解决! :D – pmfith

+0

非常欢迎你,彼得! :-) – RuslanDev