Skip to main content
Solved

Duplicate records when adding new entries to a table


Hi,

I’m having trouble with one of my projects.

I created a screen linked to a table I made. When I select my client through the selector, the client’s data is displayed in the designated fields.

 

However, when I try to add new data by pressing the "+", I encounter a problem: the default client ID is set to -2147483647. When I enter information into the form and save, two rows are created in the table—one with a new ID but empty fields, and another with the values I entered into the form.

 

Best answer by darylbowman

Try replacing ClientID with this:

#region ClientID
[PXDBIdentity(IsKey = true)]
[PXUIField(DisplayName = "Client ID")]
[PXSelector(
    typeof(Search<SanitationCustomer.clientID>),
    typeof(SanitationCustomer.clientID),
    typeof(SanitationCustomer.name),
    DescriptionField = typeof(SanitationCustomer.name)
)]
public virtual int? ClientID { get; set; }
public abstract class clientID : PX.Data.BQL.BqlInt.Field<clientID> { }
#endregion

 

View original
Did this topic help you find an answer to your question?

5 replies

darylbowman
Captain II
Forum|alt.badge.img+13

Please post your DAC definition and a basic version of your Graph


  • Author
  • Freshman I
  • 3 replies
  • October 9, 2024
using System;
using PX.Data;
using PX.Data.ReferentialIntegrity.Attributes;
using PX.Data.BQL.Fluent;
using PX.Objects.CS;

namespace Assainissement
{
    [Serializable]
    [PXCacheName("Sanitation Customer")]
    public class SanitationCustomer : IBqlTable
    {
        #region ClientID
        [PXDBIdentity(IsKey = true)]
        [PXUIField(DisplayName = "Client ID")]
        [PXParent(typeof(Select<SanitationCustomer, Where<SanitationCustomer.clientID, Equal<Current<SanitationCustomer.clientID>>>>))]
        [PXSelector(
            typeof(Search<SanitationCustomer.clientID>),
            typeof(SanitationCustomer.clientID),
            typeof(SanitationCustomer.name),
            SubstituteKey = typeof(SanitationCustomer.clientID),
            DescriptionField = typeof(SanitationCustomer.name)
        )]
        public virtual int? ClientID { get; set; }
        public abstract class clientID : PX.Data.BQL.BqlInt.Field<clientID> { }
        #endregion


        #region BreweryID
        [PXInt]
        [PXUIField(DisplayName = "Selected BreweryID", Visibility = PXUIVisibility.Visible)]
        [PXDBDefault(typeof(SanitationCustomer.clientID), PersistingCheck = PXPersistingCheck.Nothing)]
        public virtual int? BreweryID { get; set; }
        public abstract class breweryID : PX.Data.BQL.BqlInt.Field<breweryID> { }
        #endregion  


        #region Name
        [PXDBString(80, IsUnicode = true)]
        [PXUIField(DisplayName = "Name")]
        public virtual string Name { get; set; }
        public abstract class name : PX.Data.BQL.BqlString.Field<name> { }
        #endregion

        #region Address
        [PXDBString(50, IsUnicode = true)]
        [PXUIField(DisplayName = "Address")]
        public virtual string Address { get; set; }
        public abstract class address : PX.Data.BQL.BqlString.Field<address> { }
        #endregion

        #region City
        [PXDBString(50, IsUnicode = true)]
        [PXUIField(DisplayName = "City")]
        public virtual string City { get; set; }
        public abstract class city : PX.Data.BQL.BqlString.Field<city> { }
        #endregion

        #region PostalCode
        [PXDBString(10, IsUnicode = true)]
        [PXUIField(DisplayName = "Postal Code")]
        public virtual string PostalCode { get; set; }
        public abstract class postalCode : PX.Data.BQL.BqlString.Field<postalCode> { }
        #endregion

        #region Phone
        [PXDBString(50, IsUnicode = true)]
        [PXUIField(DisplayName = "Phone")]
        public virtual string Phone { get; set; }
        public abstract class phone : PX.Data.BQL.BqlString.Field<phone> { }
        #endregion

        #region Email
        [PXDBString(50, IsUnicode = true)]
        [PXUIField(DisplayName = "Email")]
        public virtual string Email { get; set; }
        public abstract class email : PX.Data.BQL.BqlString.Field<email> { }
        #endregion

        #region EmailPreference
        [PXDBBool]
        [PXUIField(DisplayName = "Notification par courriel")]
        public virtual bool? EmailPreference { get; set; }
        public abstract class emailPreference : PX.Data.BQL.BqlBool.Field<emailPreference> { }
        #endregion

        #region Status
        [PXDBString(50, IsUnicode = true)]
        [PXUIField(DisplayName = "Status")]
        [PXStringList(new string[] { "Ouvert", "Fermé définitivement", "Fermé temporairement", "Rénovation", "Saisonnier", "Lignes non utilisées" }, new string[] { "Ouvert", "Fermé définitivement", "Fermé temporairement", "Rénovation", "Saisonnier", "Lignes non utilisées" })]
        public virtual string Status { get; set; }
        public abstract class status : PX.Data.BQL.BqlString.Field<status> { }
        #endregion
    }
}

 

using PX.Data;
using PX.Data.BQL.Fluent;

namespace Assainissement
{
    public class ClientSanitationMaint : PXGraph<ClientSanitationMaint, SanitationCustomer>
    {
        public PXSelect<SanitationCustomer> SanitationCustomers;

        public PXSave<SanitationCustomer> Save;
        public PXCancel<SanitationCustomer> Cancel;

        protected virtual void _(Events.RowInserted<SanitationCustomer> e)
        {
            if (e.Row != null)
            {
                PXTrace.WriteInformation($"RowInserted: ClientID = {e.Row.ClientID}");
            }
        }

    }
}

 


darylbowman
Captain II
Forum|alt.badge.img+13
  • 1704 replies
  • Answer
  • October 9, 2024

Try replacing ClientID with this:

#region ClientID
[PXDBIdentity(IsKey = true)]
[PXUIField(DisplayName = "Client ID")]
[PXSelector(
    typeof(Search<SanitationCustomer.clientID>),
    typeof(SanitationCustomer.clientID),
    typeof(SanitationCustomer.name),
    DescriptionField = typeof(SanitationCustomer.name)
)]
public virtual int? ClientID { get; set; }
public abstract class clientID : PX.Data.BQL.BqlInt.Field<clientID> { }
#endregion

 


  • Author
  • Freshman I
  • 3 replies
  • October 9, 2024

Thank you man! Worked like a charm! 


darylbowman
Captain II
Forum|alt.badge.img+13

I’m not certain which thing was doing it, but [PXParent] is for associating detail records with master records, and since you don’t have a surrogate key, you don’t need to specify SubstituteKey.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings