Solved

Added two Grids to the Customer Location Screen, both error on save saying Location ID cannot be 0

  • 17 October 2022
  • 7 replies
  • 100 views

Userlevel 3
Badge

Added two grids to the Customer Locations Screen.  The screens work fine up to the point where I hit save. Then it says it cannot set Location ID cannot be empty.  So Location ID is not being grabbed by the data view I assume.  

The Definitions of the two data views are below: 



namespace LocationTab
{
  public class CustomerLocationMaint_Extension : PXGraphExtension<CustomerLocationMaint>
  {
    #region Event Handlers   

    public PXSelect<InvoiceRatesDetail, Where<InvoiceRatesDetail.locationID, Equal<Current<Location.locationID>>>> InvoiceRates;
    public PXSelect<SettlementDetail, Where<SettlementDetail.locationID, Equal<Current<Location.locationID>>>> InvoiceSettlement;



    #endregion
  }
}

 

For the data definition in code (table one InvoiceRatesDetail): 

 #region LocationID
    [PXDBInt(IsKey=true)]
    [PXDBDefault(typeof(Location.locationID))]
    [PXParent(typeof(Select<Location, Where<Location.locationID, Equal<Current<InvoiceRatesDetail.locationID>>>>))]
    [PXUIField(DisplayName = "Location ID")]
    public virtual int? LocationID { get; set; }
    public abstract class locationID : PX.Data.BQL.BqlInt.Field<locationID> { }
    #endregion

(table two SettlementDetail):

 #region LocationID
    [PXDBInt(IsKey=true)]
    [PXDBDefault(typeof(Location.locationID))]
    [PXParent(typeof(Select<Location, Where<Location.locationID, Equal<Current<SettlementDetail.locationID>>>>))]
    [PXUIField(DisplayName = "Location ID")]
    public virtual int? LocationID { get; set; }
    public abstract class locationID : PX.Data.BQL.BqlInt.Field<locationID> { }
    #endregion

 

Error message on save:

 

Any help would be appreciated

 

 

icon

Best answer by Fernando Amadoz 17 October 2022, 23:21

View original

7 replies

Wrong account - see my response below

Userlevel 5
Badge +2

@edwardmcgovern97

The original Location DAC also includes BAccountID as part of the primary key.

Try to include BAccountID field in your table definition - with PXDBDefault attribute as well - and redefine the Data view as

		public PXSelect<InvoiceRatesDetail, Where<InvoiceRatesDetail.bAccountID, Equal<Current<Location.bAccountID>>, And<InvoiceRatesDetail.locationID, Equal<Current<Location.locationID>>>>> InvoiceRates;

Notice the definition of LocationCurrent and Opportunities data views, following a similar structure.

Userlevel 3
Badge

I did not include the bAccountID in the new tables and of course not part of the views because of it (didn’t see Customer ID and it threw me off. Thanks for pointing that out.

 

I have added to both tables the bAccountID 

and changed the pxparent in both  DAC definitions to have where clauses with both baccountid and locationid 

 

 #region bAccountID
    [PXDBInt(IsKey=true)]
    [PXDBDefault(typeof(Location.bAccountID))]                                      
    [PXParent(typeof(Select<Location, Where<Location.bAccountID, Equal<Current<InvoiceRatesDetail.bAccountID>>, And<Location.locationID, Equal<Current<InvoiceRatesDetail.locationID>>>>>))]
    [PXUIField(DisplayName = "Customer ID")]
    public virtual int? BAccountID { get; set; }
    public abstract class bAccountID : PX.Data.BQL.BqlInt.Field<bAccountID> { }

    #endregion
      
    #region LocationID
    [PXDBInt(IsKey=true)]
    [PXDBDefault(typeof(Location.locationID))]
    [PXParent(typeof(Select<Location, Where<Location.bAccountID, Equal<Current<InvoiceRatesDetail.bAccountID>>, And<Location.locationID, Equal<Current<InvoiceRatesDetail.locationID>>>>>))]
    [PXUIField(DisplayName = "Location ID")]
    public virtual int? LocationID { get; set; }
    public abstract class locationID : PX.Data.BQL.BqlInt.Field<locationID> { }
    #endregion

 

I have updated the views to filter both on baccountid and locationid

 

 public PXSelect<InvoiceRatesDetail, Where<InvoiceRatesDetail.bAccountID, Equal<Current<Location.bAccountID>>, And<InvoiceRatesDetail.locationID, Equal<Current<Location.locationID>>>>> InvoiceRates;
    public PXSelect<SettlementDetail, Where<SettlementDetail.bAccountID, Equal<Current<Location.bAccountID>>, And<SettlementDetail.locationID, Equal<Current<Location.locationID>>>>> InvoiceSettlement;

    
 

This time I get both cannot be empty:  

 

 

Userlevel 5
Badge +2

@edwardmcgovern97 please share the customization package in order to test it locally.

Userlevel 3
Badge

Its the two grids on AR303020 Rates and Settlements

Userlevel 3
Badge

Sorry did not put one of the table scirpts

Userlevel 5
Badge +2

@edwardmcgovern97 the issue is related to the definition of the [PXDBDefault] attribute.

You have it defined as  [PXDBDefault(typeof(Location.bAccountID))]    

which, based on the combination of libraries indicated in the class, it’s taking the PX.Objects.CR.Standalone.Location class

 

However, it should be using PX.Objects.CR.Location instead.

The PXDBDefault attributes should be defined as this:

[PXDBDefault(typeof(PX.Objects.CR.Location.bAccountID))]

I am attaching a simplified version of the customization project for your reference.

----- 

You could see this incorrect defaulting behavior by adding the BAccountID and LocationID columns to the grid. When new lines were being added, the fields remained blank, instead of predefaulting the header values.

-----

Note: It’s likely that PXParent attribute should be adjusted too, but I have not tested this.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved