使用acumatica系统中的webservices API在屏幕Bill And Adjusment中导入金额

时间:2017-01-12 04:47:48

标签: c# web-services acumatica

我需要使用webservices将Amount Paid的值导入Acumatica ERP系统。请参阅下面的截图。

enter image description here

我已经使用参考编号=" 1700000016",DocType =" Bill",VendorRef =" SV-889-JKT-2"创建了一些代码, VendorID =" V000000030"和支付金额=" 1,250,000"。请参考下面的代码。

   sCon.getLogin(username, password, url, context);
            AP301000Content konten = context.AP301000GetSchema();
            //context.AP301000Clear();
            List<Command> oCmds = new List<Command>();

            //oCmds.Add(konten.Actions.Insert);
            //--------------- adding header transaction -----------------//
            konten.DocumentSummary.Type.Commit = false;
            konten.DocumentSummary.Type.LinkedCommand = null;
            oCmds.Add(new Value { LinkedCommand = konten.DocumentSummary.Type, Value = "Bill" });
            oCmds.Add(new Value { LinkedCommand = konten.DocumentSummary.ReferenceNbr, Value = "0000" });
            oCmds.Add(new Value { LinkedCommand = konten.DocumentSummary.Date, Value = dtDateSV.Text });
            oCmds.Add(new Value { LinkedCommand = konten.DocumentSummary.VendorRef, Value = "SV-889-JKT-2" });
            oCmds.Add(new Value { LinkedCommand = konten.DocumentSummary.Vendor, Value = "V000000030" });

            //-------------- adding detail transaction (Based on values in Data Grid )-------------
            int a = dgvDocDetailSV.Rows.Count;
            for (int x = 0; x < a; x++)
            {
                oCmds.Add(konten.DocumentDetails.ServiceCommands.NewRow);
                oCmds.Add(new Value { LinkedCommand = konten.DocumentDetails.Branch, Value = dgvDocDetailSV.Rows[x].Cells[1].Value.ToString() });
                oCmds.Add(new Value { LinkedCommand = konten.DocumentDetails.InventoryID, Value = dgvDocDetailSV.Rows[x].Cells[2].Value.ToString() });
                oCmds.Add(new Value { LinkedCommand = konten.DocumentDetails.JobOrderNbr, Value = dgvDocDetailSV.Rows[x].Cells[3].Value.ToString() });
                oCmds.Add(new Value { LinkedCommand = konten.DocumentDetails.Quantity, Value = dgvDocDetailSV.Rows[x].Cells[4].Value.ToString() });
                oCmds.Add(new Value { LinkedCommand = konten.DocumentDetails.UOM, Value = dgvDocDetailSV.Rows[x].Cells[5].Value.ToString() });
                oCmds.Add(new Value { LinkedCommand = konten.DocumentDetails.UnitCost, Value = dgvDocDetailSV.Rows[x].Cells[6].Value.ToString() });
            }
            //------ add document in Applications Tab Menu -------//
            string DocTypePrepayment = "Prepayment";
            string RefNbrPrepayment = "1700000015";
            oCmds.Add(new Key
            {
                ObjectName = konten.Applications.DocTypeDisplayDocType.ObjectName,
                FieldName = konten.Applications.DocTypeDisplayDocType.FieldName,
                Value = DocTypePrepayment
            });
            oCmds.Add(new Key
            {
                ObjectName = konten.Applications.ReferenceNbrDisplayRefNbr.ObjectName,
                FieldName = konten.Applications.ReferenceNbrDisplayRefNbr.FieldName,
                Value = RefNbrPrepayment
            });
            oCmds.Add(new Value { LinkedCommand = konten.Applications.AmountPaid, Value = "1250000" });

            //------ save transaction in acumatica -------//
            oCmds.Add(konten.Actions.Save);
            var result = context.AP301000Submit(oCmds.ToArray());

尝试导入此数据后出现错误消息。错误消息是&#34; System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---&GT; PX.Data.PXException:错误#111:处理字段CuryAdjdAmt时发生错误:对象引用未设置为对象的实例.. ---&gt; System.NullReferenceException:未将对象引用设置为对象的实例。 &#34 ;. 字段CuryAdjdAmt似乎为null,并且此字段映射到Acumatica System的“应用程序菜单”选项卡中的AmountPaid字段。

请给我参考解决这个问题。 感谢

1 个答案:

答案 0 :(得分:0)

看起来调整数据视图委托存在问题,这是由我们在一年前为“帐单和调整”屏幕所做的性能改进造成的。我已将所有细节转发给Acumatica工程团队进行进一步调查。

作为临时解决方法,您可以为APInvoiceEntry BLC实现扩展,并稍微更改调整数据视图的委托:

public class APInvoiceEntryExt : PXGraphExtension<APInvoiceEntry>
{
    [PXCopyPasteHiddenView]
    public PXSelectJoin<APAdjust,
        InnerJoin<APPayment, On<APPayment.docType, Equal<APAdjust.adjgDocType>,
            And<APPayment.refNbr, Equal<APAdjust.adjgRefNbr>>>>> Adjustments;

    public IEnumerable adjustments()
    {
        IEnumerable result;

        bool origIsImport = Base.IsImport;
        Base.IsImport = false;
        try
        {
            result = Base.Adjustments.Select();
        }
        finally
        {
            Base.IsImport = origIsImport;
        }

        return result;
    }
}

通过应用临时解决方法,我可以使用以下命令集更新AmountPaid字段。鉴于调整数据视图中的复杂程度(因为它必须处理从数据库检索并在运行时创建的记录),当“应用程序”选项卡中有多个文档时,必须使用RowNumber服务命令(屏幕 - 遗憾的是,基于Key类型的API命令无法在“应用程序”选项卡中找到记录。

以下示例将向Acumatica API发送2个请求: - 第一次调用从“应用程序”选项卡导出所有记录 - 通过循环返回数组,您可以确定哪些是记录的RowNumbers,需要为AmountPaid设置新的值 - 在第二次调用时,传递RowNumber并将新值分配给AmountPaid字段

Screen context = new Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.Url = "http://localhost/AP301000/Soap/AP301000.asmx";
context.Login("admin", "123");

Content billSchema = context.GetSchema();

// 1st call to export all records from the Applications tab
billSchema.DocumentSummary.Type.Commit = false;
billSchema.DocumentSummary.Type.LinkedCommand = null;

var commands = new Command[]
{
    new Value
    {
        Value = "Bill",
        LinkedCommand = billSchema.DocumentSummary.Type
    },
    new Value
    {
        Value = "000927",
        LinkedCommand = billSchema.DocumentSummary.ReferenceNbr
    },
    billSchema.Applications.DocTypeDisplayDocType,
    billSchema.Applications.ReferenceNbrDisplayRefNbr,
    billSchema.Applications.Balance
};
var applications = context.Submit(commands).ToList();
// end of 1st call to export all records from the Applications tab

// 2nd call to set AmountPaid in the Applications tab
var cmds = new List<Command>();
foreach (var application in applications)
{
    cmds.Add(
        new Value
        {
            Value = applications.IndexOf(application).ToString(),
            LinkedCommand = billSchema.Applications.ServiceCommands.RowNumber
        });
    cmds.Add(
        new Value
        {
            Value = application.Applications.Balance.Value,
            LinkedCommand = billSchema.Applications.AmountPaid
        });
}
cmds.Add(billSchema.Actions.Save);
context.Submit(cmds.ToArray());
// end of 2nd call to set AmountPaid in the Applications tab