使用Acumatica API删除位置

时间:2015-03-26 01:04:28

标签: acumatica

我想删除一个客户的位置记录。我以前从未删除任何内容,我在StackOverflow或Acumatica提供的示例中没有看到任何示例。看起来像使用关键字段进行提交并且删除命令是有意义的,但这给了我一个非常含糊的“对象引用未设置为对象的实例”。错误。任何人都可以告诉我这里我做错了什么,或者这是否是错误的方法?代码和完整的错误消息如下。

Public Function DeleteLocation(ByVal customerID As String, ByVal locID As String) As Boolean
    Dim address As CR303010Content = m_context.CR303010GetSchema()
    m_context.CR303010Clear()

    Dim customerVal As New Value() With {.LinkedCommand = address.LocationSummary.Customer, .Value = customerID}
    Dim idVal As New Value() With {.LinkedCommand = address.LocationSummary.LocationID, .Value = locID}

    ' execute delete
    Dim deleteCommands As Command() = {customerVal, idVal, address.Actions.Delete}
    Dim deleteResult As CR303010Content() = m_context.CR303010Submit(deleteCommands)

    Return True

End Function

引发此异常:

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> 
System.NullReferenceException: Object reference not set to an instance of an object.
at PX.Objects.CR.LocationMaintBase`3.Location_RowDeleted(PXCache cache, PXRowDeletedEventArgs e)
at PX.Data.PXCache.OnRowDeleted(Object item, Boolean externalCall)
at PX.Data.PXCache`1.Delete(Object data, Boolean bypassinterceptor)
at PX.Data.PXCache`1.Delete(Object data, Boolean bypassinterceptor)
at PX.Data.PXCache`1.Delete(Object data)
at PX.Data.PXDelete`1.<Handler>d__0.MoveNext()
at PX.Data.PXAction`1.<Press>d__c.MoveNext()
at PX.Data.PXAction`1.<Press>d__c.MoveNext()
at PX.Api.SyImportProcessor.SyStep.CommitChanges(Object itemToBypass, PXFilterRow[] targetConditions)
at PX.Api.SyImportProcessor.ExportTableHelper.ExportTable()
at PX.Api.ScreenUtils.Submit(String screenId, Command[] commands, SchemaMode schemaMode, PXGraph graph)
at PX.Api.Services.ScreenService.Submit(String id, IEnumerable`1 commands, SchemaMode schemaMode)
at PX.Api.Soap.Screen.ScreenGate.Submit(Command[] commands)
--- End of inner exception stack trace ---

3 个答案:

答案 0 :(得分:1)

您的代码是正确的,但在删除不使用默认地址或联系信息的位置时会失败。这是由于影响所有Acumatica版本的错误。解决方法是在删除位置之前重新检查“使用默认值”。该问题已被报道,目前正在修复中。感谢您帮助Eric解决此问题,并对由此带来的不便表示歉意。

答案 1 :(得分:0)

我可以提出丑陋的方式:PXDatabase.Delete。它将直接在db中生成delete语句。例如在C#中:

PXDatabase.Delete(新的PXDataFieldRestrict(&#34; RefNbr&#34;,row.APRefNbr),新的PXDataFieldRestrict(&#34; DocType&#34;,&#34; INV&#34;));                                 PXDatabase.Delete(新的PXDataFieldRestrict(&#34; RefNbr&#34;,row.APRefNbr),新的PXDataFieldRestrict(&#34; DocType&#34;,&#34; INV&#34;));

答案 2 :(得分:0)

以下代码可以正常使用

            Content CR303010 = context.GetSchema();
        context.Clear();

        context.Submit(
            new Command[]
            {
                new Value { Value = "ABARTENDE", LinkedCommand = CR303010.LocationSummary.BusinessAccount, Commit = true },
                new Value { Value = "TEST2", LinkedCommand = CR303010.LocationSummary.LocationID, Commit = true },
                CR303010.Actions.Delete
            }
        );