微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Acumatica - 详细记录不使用主记录的自动编号字段

如何解决Acumatica - 详细记录不使用主记录的自动编号字段

我在 Acumatica 2020R2 中有一个维护表单,它在表单和包含网格的两个选项卡项之间具有主从关系。我有表单自动编号的 ID,详细记录使用此 ID 和 PXParentAttribute。表单自动编号并使用正确的 ID 保存到数据库中,但详细记录使用初始占位符 NEW> 而不是自动保存到数据库中号。

以下是表单使用的 DAC 字段:

        #region vendorRebateID
        [PXDBString(15,IsKey = true,IsUnicode = true,InputMask = ">CCCCCCCCCCCCCCC")]
        [PXDefault(PersistingCheck = PXPersistingCheck.NullOrBlank)]
        [PXUIField(displayName = "vendor Rebate Code",Visibility = PXUIVisibility.SelectorVisible)]
        [AutoNumber(typeof(APvendorRebateSetup.numberingID),typeof(AccessInfo.businessDate))]
        [PXSelector(typeof(Search<APvendorRebate.vendorRebateID>))]
        public virtual string vendorRebateID { get; set; }
        public abstract class vendorRebateID : PX.Data.BQL.BqlString.Field<vendorRebateID> { }
        #endregion

        #region Description
        [PXDBString(256,InputMask = "")]
        [PXUIField(displayName = "Description")]
        public virtual string Description { get; set; }
        public abstract class description : PX.Data.BQL.BqlString.Field<description> { }
        #endregion

        #region vendorID
        [vendor]
        [PXDefault]
        [PXParent(typeof(Select<vendor,Where<vendor.bAccountID,Equal<Current<APvendorPrice.vendorID>>>>))]
        public virtual int? vendorID { get; set; }
        public abstract class vendorID : PX.Data.BQL.BqlInt.Field<vendorID> { }
        #endregion

        #region CuryID
        [PXDBString(5)]
        [PXDefault(typeof(Search<PX.Objects.GL.Company.baseCuryID>))]
        [PXSelector(typeof(Currency.curyID),CacheGlobal = true)]
        [PXUIField(displayName = "Currency",required = false,Visible = false,Visibility = PXUIVisibility.Visible)]
        public virtual string CuryID { get; set; }
        public abstract class curyID : PX.Data.BQL.BqlString.Field<curyID> { }
        #endregion

        #region EffectiveDate
        [PXDefault(typeof(AccessInfo.businessDate),PersistingCheck = PXPersistingCheck.nothing)]
        [PXDBDate()]
        [PXUIField(displayName = "Effective Date",Visibility = PXUIVisibility.Visible)]
        public virtual DateTime? EffectiveDate { get; set; }
        public abstract class effectiveDate : PX.Data.BQL.BqlDateTime.Field<effectiveDate> { }
        #endregion

        #region ExpirationDate
        [PXDBDate()]
        [PXUIField(displayName = "Expiration Date",Visibility = PXUIVisibility.Visible)]
        public virtual DateTime? ExpirationDate { get; set; }
        public abstract class expirationDate : PX.Data.BQL.BqlDateTime.Field<expirationDate> { }
        #endregion

以下是其中一个网格使用的 DAC 字段:

        #region vendorRebateID
        [PXDBString(15,InputMask = "")]
        [PXDefault(typeof(APvendorRebate.vendorRebateID))]
        [PXParent(typeof(SelectFrom<APvendorRebate>.
            Where<APvendorRebate.vendorRebateID.IsEqual<APvendorRebateCustomer.vendorRebateID.FromCurrent>>))]
        public virtual string vendorRebateID { get; set; }
        public abstract class vendorRebateID : PX.Data.BQL.BqlString.Field<vendorRebateID> { }
        #endregion

        #region CustomerID
        [PX.Objects.AR.Customer(DescriptionField = typeof(PX.Objects.AR.Customer.acctName),IsKey = true)]
        [PXUIField(displayName = "Customer")]
        public virtual int? CustomerID { get; set; }
        public abstract class customerID : PX.Data.BQL.BqlInt.Field<customerID> { }
        #endregion

以下是其他网格使用的 DAC 字段:

        #region vendorRebateID
        [PXDBString(15,InputMask = "")]
        [PXDefault(typeof(APvendorRebate.vendorRebateID))]
        [PXParent(typeof(SelectFrom<APvendorRebate>.
            Where<APvendorRebate.vendorRebateID.IsEqual<APvendorRebateInventoryItem.vendorRebateID.FromCurrent>>))]
        public virtual string vendorRebateID { get; set; }
        public abstract class vendorRebateID : PX.Data.BQL.BqlString.Field<vendorRebateID> { }
        #endregion

        #region InventoryID
        [APCrossItem(BAccountField = typeof(APvendorRebate.vendorID),WarningOnNonUniqueSubstitution = true)]
        [PXParent(typeof(Select<InventoryItem,Where<InventoryItem.inventoryID,Equal<Current<APvendorPrice.inventoryID>>>>))]
        public virtual int? InventoryID { get; set; }
        public abstract class inventoryID : PX.Data.BQL.BqlInt.Field<inventoryID> { }
        #endregion

        #region AlternateID
        [PXUIField(displayName = "Alternate ID")]
        [PXDBString(50,InputMask = "")]
        public virtual string AlternateID { get; set; }
        public abstract class alternateID : PX.Data.BQL.BqlString.Field<alternateID> { }
        #endregion

        #region UOM
        [PXDefault(typeof(Search<InventoryItem.purchaseUnit,Equal<Current<APvendorPrice.inventoryID>>>>))]
        [INUnit(typeof(APvendorPrice.inventoryID))]
        [PXFormula(typeof(Selector<APvendorPrice.inventoryID,InventoryItem.purchaseUnit>))]
        public virtual string UOM { get; set; }
        public abstract class uOM : PX.Data.BQL.BqlString.Field<uOM> { }
        #endregion

        #region "Rebate Selling Price"
        [PXDBPriceCost]
        [PXUIField(displayName = "Selling Price",Visibility = PXUIVisibility.Visible)]
        public virtual decimal? SellingPrice { get; set; }
        public abstract class sellingPrice : PX.Data.BQL.BqlDecimal.Field<sellingPrice> { }
        #endregion

        #region RebatePrice
        [PXDBPriceCost]
        [PXDefault(TypeCode.Decimal,"0.0")]
        [PXUIField(displayName = "Rebate Price",Visibility = PXUIVisibility.Visible)]
        public virtual decimal? RebatePrice { get; set; }
        public abstract class rebatePrice : PX.Data.BQL.BqlDecimal.Field<rebatePrice> { }
        #endregion

        #region vendorPrice
        [PXPriceCost]
        [PXUIField(displayName = "vendor Price",Enabled = false)]
        [PXDependsOnFields(typeof(APvendorRebate.vendorID),typeof(APvendorRebateInventoryItem.inventoryID),typeof(APvendorRebate.effectiveDate),typeof(APvendorRebate.expirationDate))]
        [LatestvendorPrice]
        public virtual decimal? vendorPrice { get; set; }
        public abstract class vendorPrice : PX.Data.BQL.BqlDecimal.Field<vendorPrice> { }
        #endregion

        #region BreakQty
        [PXDefault(TypeCode.Decimal,"0.0")]
        [PXDBQuantity(MinValue = 0)]
        [PXUIField(displayName = "Break Qty",Visibility = PXUIVisibility.Visible)]
        public virtual decimal? BreakQty { get; set; }
        public abstract class breakQty : PX.Data.BQL.BqlDecimal.Field<breakQty> { }
        #endregion

        #region SiteID
        [NullableSite]
        public virtual int? SiteID { get; set; }
        public abstract class siteID : PX.Data.BQL.BqlDecimal.Field<siteID> { }
        #endregion

这里是ASPX代码

<%@ Page Language="C#" MasterPageFile="~/MasterPages/FormView.master" AutoEventWireup="true" ValidateRequest="false" CodeFile="AP209900.aspx.cs" Inherits="Page_AP209900" Title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MasterPages/FormView.master" %>

<asp:Content ID="cont1" ContentPlaceHolderID="phDS" Runat="Server">
  <px:PXDataSource Height="" ID="ds" runat="server" Visible="True" Width="100%"
        TypeName="APvendorRebates.APvendorRebateMaint"
        PrimaryView="Rebates"
        >
    <CallbackCommands>

    </CallbackCommands>
  </px:PXDataSource>
</asp:Content>
<asp:Content ID="cont2" ContentPlaceHolderID="phF" Runat="Server">
  <px:PXFormView AllowCollapse="false" Height="" ID="form" runat="server" DataSourceID="ds" DataMember="Rebates" Width="100%" AllowAutoHide="false">
    <Template>
      <px:PXLayoutRule runat="server" ID="PXLayoutRule1" StartRow="True" ></px:PXLayoutRule>
      <px:PXLayoutRule ControlSize="XM" StartGroup="False" SuppressLabel="False" LabelsWidth="SM" runat="server" ID="CstPXLayoutRule1" StartColumn="True" ></px:PXLayoutRule>
      <px:PXSelector CommitChanges="True" runat="server" ID="CstPXSelector6" datafield="vendorRebateID" >
        <GridProperties>
          <Layout BorderMode="NotSet" CellPadding="0" CellSpacing="0" ></Layout></GridProperties></px:PXSelector>
      <px:PXSegmentMask CommitChanges="True" runat="server" ID="CstPXSegmentMask4" datafield="vendorID" ></px:PXSegmentMask>
      <px:PXLayoutRule runat="server" ID="CstLayoutRule21" ColumnSpan="2" ></px:PXLayoutRule>
      <px:PXTextEdit runat="server" ID="CstPXTextEdit10" datafield="Description" ></px:PXTextEdit>
      <px:PXLayoutRule StartRow="False" ControlSize="SM" StartGroup="False" SuppressLabel="False" LabelsWidth="SM" runat="server" ID="CstPXLayoutRule2" StartColumn="True" ></px:PXLayoutRule>
      <px:PXDateTimeEdit CommitChanges="True" runat="server" ID="CstPXDateTimeEdit7" datafield="EffectiveDate" ></px:PXDateTimeEdit>
      <px:PXDateTimeEdit CommitChanges="True" runat="server" ID="CstPXDateTimeEdit8" datafield="ExpirationDate" ></px:PXDateTimeEdit></Template>
    <AutoSize Container="Parent" Enabled="False" MinHeight="140" ></AutoSize>
  </px:PXFormView>
  <px:PXTab Height="" runat="server" ID="CstPXTab14">
    <Items>
      <px:PXTabItem Repaintondemand="False" BindingContext="form" Text="Inventory Items" >
        <Template>
          <px:PXGrid SyncPosition="False" Width="100%" runat="server" ID="CstPXGrid15" SkinID="Details">
            <Levels>
              <px:PXGridLevel DataMember="InventoryItems" >
                <Columns>
                  <px:PXGridColumn CommitChanges="True" datafield="InventoryID" Width="70" ></px:PXGridColumn>
                  <px:PXGridColumn datafield="InventoryID_description" Width="280" ></px:PXGridColumn>
                  <px:PXGridColumn datafield="AlternateID" Width="180" ></px:PXGridColumn>
                  <px:PXGridColumn datafield="UOM" Width="72" ></px:PXGridColumn>
                  <px:PXGridColumn datafield="SellingPrice" Width="100" ></px:PXGridColumn>
                  <px:PXGridColumn datafield="RebatePrice" Width="100" ></px:PXGridColumn>
                  <px:PXGridColumn datafield="vendorPrice" Width="100" ></px:PXGridColumn>
                  <px:PXGridColumn datafield="BreakQty" Width="100" ></px:PXGridColumn>
                  <px:PXGridColumn datafield="SiteID" Width="140" ></px:PXGridColumn></Columns>
                <RowTemplate></RowTemplate></px:PXGridLevel></Levels>
            <AutoSize Enabled="True" ></AutoSize>
            <Mode InitNewRow="True" ></Mode></px:PXGrid></Template></px:PXTabItem>
      <px:PXTabItem Repaintondemand="False" BindingContext="form" Text="Customers" >
        <Template>
          <px:PXGrid SyncPosition="False" runat="server" ID="CstPXGrid16" Width="100%" SkinID="Details">
            <Levels>
              <px:PXGridLevel DataMember="Customers" >
                <Columns>
                  <px:PXGridColumn datafield="CustomerID" Width="140" CommitChanges="True" ></px:PXGridColumn>
                  <px:PXGridColumn datafield="CustomerID_description" Width="280" ></px:PXGridColumn></Columns>
                <RowTemplate></RowTemplate></px:PXGridLevel></Levels>
            <AutoSize Enabled="True" ></AutoSize>
            <Mode InitNewRow="True" ></Mode></px:PXGrid></Template></px:PXTabItem></Items>
    <AutoSize Enabled="True" />
    <AutoSize MinHeight="180" />
    <AutoSize Container="Window" /></px:PXTab></asp:Content>

以下是将记录插入数据库的方式:

enter image description here

我是 Acumatica 的新手,我根据 T210 培训课程中的说明编写了此代码。我非常仔细地遵循了这些步骤,但我不确定为什么会发生这种情况。任何帮助,将不胜感激。谢谢。

解决方法

在子 DAC 中,PXDefault 应为 PXDBDefault。这是我刚开始时的常见问题。 PXDBDefault 的不同之处在于它“用于从自动生成的键字段中分配值”。

这是使用 PXDBDefault 的子 DAC 字段的一个非常基本的示例。本例中主表为XXDocument,子表为XXLine。关键字段是 myID。

#region MyID
[PXDBInt(IsKey = true)]
[PXDBDefault(typeof(XXDocument.myID))]
[PXParent(
    typeof(Select<XXDocument,Where<XXDocument.myID,Equal<Current<XXLine.myID>>>>)
    )]
[PXUIField(DisplayName = Messages.FldMyID)]
public virtual int? MyID { get; set; }
public abstract class myID : PX.Data.BQL.BqlInt.Field<myID> { }
#endregion

值得注意的是,我使用了 ID 与 CD 字段集。父 ID 是数据库中的 Identity 字段,Autonumber 字段是 CD 字段。我怀疑这也会导致您的问题,因此,我上面的示例可能不适合您尝试的直接操作。我发现将整数标识字段用于关键字段并将我的自动编号用作 CD(代码)字段非常重要,因为它作为数据结构更清晰,并且数据库更有效地存储/检索字符串整数。此外,您可以在不影响表关系的情况下更改 CD 值(类似于在 InventoryItem 中的处理方式)。

父表的 ID/CD 字段如下所示:

#region MyID
[PXDBIdentity]
public virtual int? MyID { get; set; }
public abstract class myID : PX.Data.BQL.BqlInt.Field<myID> { }
#endregion

#region MyCD
[PXDBString(15,IsKey = true,IsUnicode = true,InputMask = "")]
[PXDefault]
[AutoNumber(typeof(XXSetup.myNumberingID),typeof(AccessInfo.businessDate))]
[PXSelector(
    typeof(MyDocument.myCD),typeof(MyDocument.myCD),typeof(MyDocument.descr)
    )]
[PXUIField(DisplayName = Messages.FldMyCD,Visibility = PXUIVisibility.SelectorVisible)]
public virtual string MyCD { get; set; }
public abstract class myCD : PX.Data.BQL.BqlString.Field<myCD> { }
#endregion

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。