使用图形对象创建销售订单时出错

时间:2017-07-26 13:07:57

标签: acumatica

我正在尝试使用SOOrderEntry图形对象从PO屏幕创建销售订单。我正在使用另一个Stack Overflow案例中的技术选择分支,并且我不断收到以下错误:

enter image description here

我无法弄清楚为什么会出现这个错误,因为我正在设置CustomerID。这是代码:

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 个答案:

答案 0 :(得分:1)

始终将PXCache Insert或Update方法调用的结果分配给某个局部变量非常重要,因此您可以进一步从缓存中更改对象,而不是与PXCache没有任何共同之处的旧记录。

这个问题应该通过以下微小变化来解决:

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