使用图形对象将记录插入AP帐单和调整

时间:2017-07-12 15:28:54

标签: acumatica

我有自定义代码,可以将记录插入到另一家公司的账单和调整中,使用一个登录到另一家公司的网络服务(我同意的cludgey解决方案)。这样可以正常工作 - 但由于需要创建的记录数量可能会有点慢。

我现在正尝试使用Bills and Adjustments图形对象(APInvoiceEntry)和DAC(APInvoice和APTran)来执行相同的输入。我遇到了一些我没有使用网络服务方法收到的错误。在界面中,当您输入某些字段时,其他字段将默认。我想知道当您使用图表插入记录时是否会发生相同的操作。如果没有,那么我假设我必须填充DAC中的每个字段而不依赖于接口的默认属性。这是正确的假设吗?我所犯的错误对我来说真的很有意义,例如:

Error: An error occurred during processing of the field Vendor value 2359 Error: PayAccountID '1931' cannot be found in the system. Please verify whether you have proper access rights to this object.

不确定为什么PayAccountID会成为一个问题,因为这个特殊值' 确实存在于系统中......

以下是我目前正在尝试使用图表对象的示例:

            APInvoiceEntry apgraph = null;
            APInvoice apinvoice = null;
            APTran aptran = null;

            //Get the dataset:
             PXResultset<xvwInterCompanyProcess> res = PXSelect<xvwInterCompanyProcess,
                                                       Where<xvwInterCompanyProcess.origRefNbr, Equal<Required<ARInvoice.refNbr>>>>.Select(new PXGraph(), arinvoice.RefNbr);

            using (PXLoginScope ls = new PXLoginScope("InterCompany@Canada"))
            {
                foreach (PXResult<xvwInterCompanyProcess> rec in res)
                {

                    xvwInterCompanyProcess icp = (xvwInterCompanyProcess)rec;

                    //Save if the RefNbr has changed - unless it's the first record...
                    if (icp.OrigRefNbr != LastRefNbr)
                    {
                        //Save if it's the next header level record - but not if it's the first time through...
                        if (Counter > 0) apgraph.Persist();

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

                        //Create new header DAC and add the header records...
                        apinvoice = new APInvoice();
                        apinvoice.DocType = icp.DocType;  //apDocType;
                        apgraph.Document.Insert(apinvoice);

                        apinvoice.DocDate = icp.DocDate;
                        apinvoice.InvoiceNbr = icp.VendorRef;
                        apinvoice.DocDesc = icp.Description;
                        apinvoice.BranchID = 6;
                        apinvoice.CuryID = "USD";

                        //Get the Vendor ID from the Vendor CD ("ZINTERPAY")...
                        BAccount bacct = (BAccount)PXSelect<BAccount, Where<BAccount.acctCD, Equal<Constants.zinterpay>>>.Select(new PXGraph<ARDocumentRelease>());
                        apinvoice.VendorID = bacct.BAccountID;

                        //Insert the header (APInvoice) record into the AP Bills graph object..
                        apgraph.Document.Update(apinvoice);
                        apgraph.Persist();
                     }
                     //...create tran level records (code left out)
                     LastRefNbr = icp.OrigRefNbr;                        
                     Counter++;
                 }
             }

1 个答案:

答案 0 :(得分:0)

只是为了澄清错误消息,即PayAccountID&#39; 1931&#39;当系统处理2359分配给供应商字段时,在系统中找不到。

错误可能由两件事引起:

  1. apgraph.Document.Insert(apinvoice)的结果未分配回apinvoice变量

  2. 由于系统将在VendorLocationID更新后重新分配默认BranchID,您应订阅APInvoice.BranchID FieldDefaulting处理程序,以便在特定分支下创建AP发票

  3. 以下是在特定分支下创建AP发票的更新代码段:

    var apgraph = PXGraph.CreateInstance<APInvoiceEntry>();
    apgraph.FieldDefaulting.AddHandler<APInvoice.branchID>((s, e) =>
    {
        e.NewValue = 17;
        e.Cancel = true;
    });
    
    var apinvoice = new APInvoice();
    apinvoice.DocType = APDocType.Invoice;
    apinvoice = apgraph.Document.Insert(apinvoice);
    
    apinvoice.DocDate = DateTime.Now;
    apinvoice.InvoiceNbr = "0!23!";
    apinvoice.DocDesc = "Demo StackOverflow Bill";
    
    BAccountR bacct = (BAccountR)PXSelect<BAccountR,
        Where<BAccountR.acctCD, Equal<Required<BAccountR.acctCD>>>>
        .Select(apgraph, "AEROCOREBE");
    apinvoice.VendorID = bacct.BAccountID;
    
    apgraph.Document.Update(apinvoice);
    apgraph.Actions.PressSave();