Acumatica – Detail Record Not using Auto-Numbered Field of Master Record

I have a maintenance form in Acumatica 2020R2 that has a master-detail relationship between a form and two tab items that contain grids. I have the ID of the form auto-numbering, and the detail records use this ID with the PXParentAttribute. The form auto-numbers and saves to the database with the correct ID, but the detail records are saving to the database with the initial placeholder <NEW> instead of the auto-number.

Here are the DAC fields that the form uses:

        #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, IsUnicode = true, 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

Here are the DAC fields that one of the grids uses:
        #region VendorRebateID
        [PXDBString(15, IsKey = true, IsUnicode = true, 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

Here are the DAC fields that the other grid uses:
        #region VendorRebateID
        [PXDBString(15, IsKey = true, IsUnicode = true, 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), IsKey = true, 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, IsUnicode = true, 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, Where<InventoryItem.inventoryID, 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

Here is the ASPX code:
<%@ 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>

Here is how the records are being inserted into the database:

Acumatica - Detail Record Not using Auto-Numbered Field of Master Record

I’m fairly new to Acumatica, and I based this code on the instructions in the T210 training course. I followed the steps very carefully, and I’m not sure why this is happening. Any help would be appreciated. Thanks.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

In the child DAC’s, the PXDefault should be PXDBDefault. This was a common problem for me when I got started. The difference for PXDBDefault is that it is “use to assign a value from the auto-generated key field”.

Here is a very basic example of the child DAC field using PXDBDefault. The master table in this example is XXDocument, and the child table is XXLine. The key field is 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

Worth noting, I use an ID vs CD set of fields. The parent ID is an Identity field in the database, and the Autonumber field is a CD field. I suspect this also is contributing to your issue, and as such, my example above may not fit directly as you are attempting it. I find it very important to use the integer identity field for key fields and my auto-numbers as a CD (code) field as it is much cleaner as a data structure and more efficient for the database to store/retrieve integer over strings. Also, you can change the CD value without impacting the table relationships (similar to how it is handled in InventoryItem).

The parent table’s ID/CD fields are shown below:

#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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x