Skip to main content
Question

Key Blanks after Entry

  • December 19, 2024
  • 7 replies
  • 75 views

Forum|alt.badge.img+1

I have created a DAC with two keys and an Identity field. I can view and edit existing records fine, however when I create a new record and enter in a new key value as soon as I leave the field it blanks. Both Key fields blank after I focus is lost.

Any Ideal? 

   [Serializable]
[PXCacheName("MLS Listing")]
[PXPrimaryGraph(typeof(MLSListingList))]
public class GPMLSListing : PXBqlTable, IBqlTable
{

public class PK : PrimaryKeyOf<GPMLSListing>.By<address1, postalCode>
{
public static GPMLSListing Find(PXGraph graph, string address1, string postalCode) => FindBy(graph, address1, postalCode);
}


#region ListingID
[PXDBIdentity( FieldName = "Property ID")]
//[PXSelector(typeof(Search<address1>), ValidateValue = false)]
public virtual int? ListingID { get; set; }
public abstract class listingID : PX.Data.BQL.BqlInt.Field<listingID> { }
#endregion

#region Selected
[PXBool]
[PXUIField(DisplayName = "Selected")]
public virtual bool? Selected { get; set; }
public abstract class selected : BqlType<IBqlBool, bool>.Field<selected> { }

#endregion

#region Address1
[PXDBString(50, IsKey = true, IsUnicode = true, InputMask = "")]
[PXDefault]
[PXUIField(DisplayName = "Address")]
//[PXCheckUnique(Where = typeof(Where<address1, Equal<Current<address1>>, And<postalCode, Equal<Current<postalCode>>>>))]
//[PXSelector(typeof(Search<address1>), ValidateValue = false)]
public virtual string Address1 { get; set; }
public abstract class address1 : PX.Data.BQL.BqlString.Field<address1> { }
#endregion

#region PostalCode
[PXDBString(20, IsKey = true)]
[PXUIField(DisplayName = "Zip")]
[PXZipValidation(typeof(Country.zipCodeRegexp), typeof(Country.zipCodeMask), typeof(country))]
//[PXSelector(typeof(Search<postalCode>), ValidateValue = false)]
[PXPersonalDataField]
public virtual string PostalCode { get; set; }
public abstract class postalCode : PX.Data.BQL.BqlString.Field<postalCode> { }
#endregion

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

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

 

7 replies

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

Is this a grid?

 


Forum|alt.badge.img+1
  • Author
  • Varsity I
  • December 20, 2024

This is in a form, Is that applicable?


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

Not to my original suggestion, no. I realized after I posted it that I was assuming it was a grid.

I’m guessing you’re trying to prevent duplicate addresses, but I would recommend not using an auto-generated key in the database and a different key in the DAC, UNLESS you choose to use a natural key (which I would recommend).


Forum|alt.badge.img+1
  • Author
  • Varsity I
  • December 20, 2024

I tried without the ListingID and found the same issue.

My goal was to allow an imports scenario to insertOrReplace based off the keys of address or postalcode. But I am really struggling.

 

Leif


Forum|alt.badge.img+1

Hi ​@Leif , did you find a fix for this?

 

I’ve got pretty much the same problem. The maintenance form for my custom table/DAC looks OK, until I type a value for the key field and tab out. That key value is then blanked. I’ve got:
 

    [PXCacheName("Third-Party Warehouse")]
    [PXPrimaryGraph(typeof(PWWarehousePlugInMaint))]
    public class PWWarehousePlugIn : PXBqlTable, IBqlTable
    {


        #region PWWarehousePlugInID
        public abstract class pWWarehousePlugInID : BqlString.Field<pWWarehousePlugInID> { }

        [PXDBString(15, IsKey =true, IsUnicode = true, InputMask = ">AAAAAAAAAAAAAAA")]
        [PXDefault(PersistingCheck = PXPersistingCheck.NullOrBlank)]
        [PXUIField(DisplayName = "3PL Warehouse", Visibility = PXUIVisibility.SelectorVisible)]
        [PXSelector(typeof(Search<pWWarehousePlugInID>)))]
        public virtual string PWWarehousePlugInID
        {
            get;
            set;
        }
        #endregion

And PWWarehousePlugInID is defined as nvarchar(15) not null, part of the primary key.
The form is a simple ‘Form’ with the view defined as:

    public class PWWarehousePlugInMaint : PXGraph<PWWarehousePlugInMaint, PWWarehousePlugIn>
{

public SelectFrom<PWWarehousePlugIn>.View Warehouse;

 


Forum|alt.badge.img+9
  • Captain II
  • January 19, 2026

@allisterchambers48 

 

What is your db declaration like?

 

Is the issue occurring when you create a new record through code or the UI?

When adding through code you should aim to do something like this:

//Your Action/Handler/Logic

yourGraph.yourView.Insert(new YourDAC
{
//Set your key value here
});

//Using this
yourGraph.yourView.Insert()

//Inserts a record with a key field "assigned",
//if you then add a value for the key

yourDAC.KeyField = SomeValue;


//This adds another record into the cache and can cause data corruption/try to save 2 records into the cache instead of one.

 


Forum|alt.badge.img+1

It was through the UI.

I think I’ve fixed it. My solution was to:

  • Remove CommitChanges from the ID field
  • Create another View “CurrentRecord” in the graph, selecting from the same DAC but having Where<id,Equals<id.fromcurrent»
  • Use this ‘CurrentRecord’ view on the screen for all fields other than the ID. The ID is still bound to the primary view on the graph and the other other fields bound to that view don’t need CommitChanges and don’t use Selectors (so a simple text field is OK).

This seems to make sense. Any postback is going to cause the primary view to requery, if the row doesn’t exist the screen is going to get blanked out. So avoid the postback against the primary view by moving selectors to a different view.

 public PXSelect<PWWarehousePlugIn, Where<pWWarehousePlugInID, Equal<Current<pWWarehousePlugInID>>>> CurrentWarehouse;