Skip to main content
Solved

Save on GridView screen creates additional blank row and attempts to save it


I have a custom table with a basic GridView screen for entry.  When entering values for the first row and clicking Save, an error is thrown saying that one of the non-nullable fields has a null value.  After some debugging, it appears that the save is trying to save the row I entered, plus a new blank row -- thus, the complaint of the null value. In fact, if I make the field nullable, it actually saves the blank row (blank except for identity field) in the db.  Also, this only happens on the first row entered.  If I add another row and save, it doesn’t happen.  My guess is maybe a table/DAC key issue that makes it want to insert instead of update, but I’ve triple checked my key references.  Does this ring a bell to anyone as something you’ve run across?

Custom Table1 and Table2 have identity keys.  Custom Table2 has a foreign key to Table1 referencing its key field.  Table1 primary key definition:
 

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

[PXDBIdentity(IsKey = true)]
public virtual int? LocationBarcodeID { get; set; }
public abstract class locationBarcodeID : PX.Data.BQL.BqlInt.Field<locationBarcodeID> { }

 

Table2 primary key and foreign key:

 

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

public new static class FK
{
    public class LocationBarcode : 
        CFLocationBarcode.PK.ForeignKeyOf<CFLocationBarcode>
            .By<CFLocationBarcode.locationBarcodeID> { }
}

[PXDBIdentity(IsKey = true)]
public virtual int? LocationTrackingID { get; set; }
public abstract class locationTrackingID : PX.Data.BQL.BqlInt.Field<locationTrackingID> { }

[PXDBInt()]
[PXUIField(DisplayName = "Location Barcode", Required = true)]
[PXSelector(...)]
public virtual int? LocationBarcodeID { get; set; }
public abstract class locationBarcodeID : PX.Data.BQL.BqlInt.Field<locationBarcodeID> { }

 

Best answer by darylbowman

For anyone finding this, try setting InitNewRow on the grid to ‘true’:

 

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

14 replies

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

Yes, absolutely have encountered this. I’m blanking on how I fixed it.


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

Could you post your graph? Is this a primary grid?


Forum|alt.badge.img+5
  • Captain II
  • 504 replies
  • December 28, 2023

You’ve set the UI to indicate that the LocationBarcodeID field is required but you haven’t set a PXDefault with any instructions around null values.


darylbowman
Captain II
Forum|alt.badge.img+13
Django wrote:

You’ve set the UI to indicate that the LocationBarcodeID field is required but you haven’t set a PXDefault with any instructions around null values.

That shouldn’t cause an issue though. It just won’t be required.


  • Author
  • Freshman I
  • 4 replies
  • December 28, 2023

Graph only contains basics…

public PXSavePerRow<CFLocationTracking> Save;
public PXCancel<CFLocationTracking> Cancel;

[PXImport(typeof(CFLocationTracking))]
public PXSelectOrderBy<CFLocationTracking, OrderBy<Asc<CFLocationTracking.sortOrder>>> 
    Records;

Only thing on the screen is the grid. It is a Primary skin grid, yes.


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

I was going to suggest PXSavePerRow, so you’re good there. Odd request, but would you mind posting a screenshot yet entering data in the grid?


  • Author
  • Freshman I
  • 4 replies
  • December 28, 2023

@Django, I tried PXDefault, PXDBDefault & PXParent.  It hasn’t helped.


  • Author
  • Freshman I
  • 4 replies
  • December 28, 2023

@darylbowman 

 

 

Error: 'Location Barcode' cannot be empty.


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

Instead of defining the Save and Cancel manually, have you tried including the primary DAC in the graph definition?
 

 : PXGraph<GraphName, DACName>

 

I recall having tried this in the past, but I can’t remember if that’s what fixed it. This will display lots of extra buttons that are unnecessary that you’ll then need to hide if this does actually fix it.


  • Author
  • Freshman I
  • 4 replies
  • December 28, 2023

@darylbowman , Thanks, but that didn’t help.


Forum|alt.badge.img+1
  • Pro I
  • 59 replies
  • December 29, 2023

@tlanzer54.old 
Can you send DB Script once


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

@tlanzer54.old - Did you figure this out?


I’m experiencing the same behaviour.
I worked out that extra empty row is inserted only if the first field that the user enters is a selector. If user starts with typing the content of a text field extra empty row is not inserted. After some debugging it looks like list of events is: 
As soon as user clicks on magnifying glass of the selector ‘RowInserting’ event is triggered. When user selects a row from selector ‘FieldVerifying’ for the selector field is triggered and straight after ‘RowInserting’ event is triggered. So the 1st ‘RowInserting’ is the one that creates the extra empty row.
If user starts to fill in the record from the a text field events are:
‘FieldVerifying’ for the text field is triggered when field looses focus and straight after ‘RowInserting’ event is triggered 
FYI below is the DAC code for the selector
 

#region BAccountID
[BAccount(DisplayName = "Subcontractor")]
[PXUIField(DisplayName = "Subcontractor", Required = true)]
public virtual int? BAccountID { get; set; }
public abstract class bAccountID : PX.Data.BQL.BqlInt.Field<bAccountID> { }
#endregion

@tlanzer54.old strange coincidence that your barcode is also a selector….
To me it looks like a bug with the selector but maybe I’m missing something somewhere...

Any suggestion appreciated


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

For anyone finding this, try setting InitNewRow on the grid to ‘true’:

 


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