Skip to main content
Question

Cannot insert null value error in custom screen


Forum|alt.badge.img+1

I have created a custom screen which contains two grids in separate tabs. one grid is a read only grid. while other grid allows to CRUD operations. In this grid I use fully custom DAC. when I trying to insert data, even when insert correct values (not null) for each column sometimes it gives “cannot insert values to columns since null”.  

Even I set values after clicking save button it inserts an empty row as above.
DAC:

using System;
using PX.Data;

namespace EMPPlanningToolR4N5
{
  [Serializable]
  [PXCacheName("PTFillerReelWidths")]
  public class PTFillerReelWidths : IBqlTable
  {
    #region Width
    [PXDBInt(IsKey = true)]
    [PXUIField(DisplayName = "Width")]
    [PXDefault(0)]
    public virtual int? Width { get; set; }
    public abstract class width : PX.Data.BQL.BqlInt.Field<width> { }
    #endregion

    #region PaperTypeID
    [PXDBString(2, IsKey = true, IsFixed = true, InputMask = "")]
    [PXUIField(DisplayName = "Paper Type ID")]
    [PXDefault("##")]
    [PXSelector(typeof(PTPaperTypes.paperTypeID),
        typeof(PTPaperTypes.paperTypeID),
        typeof(PTPaperTypes.paperTypeCD),
        SubstituteKey = typeof(PTPaperTypes.paperTypeID),
        DescriptionField = typeof(PTPaperTypes.description)
        )]
    public virtual string PaperTypeID { get; set; }
    public abstract class paperTypeID : PX.Data.BQL.BqlString.Field<paperTypeID> { }
    #endregion

    #region Gsm
    [PXDBInt(IsKey = true)]
    [PXUIField(DisplayName = "GSM")]
    [PXSelector(typeof(PTFillerReelGSMs.gsm),
        typeof(PTFillerReelGSMs.gsm)
        )]
        public virtual int? Gsm { get; set; }
    public abstract class gsm : PX.Data.BQL.BqlInt.Field<gsm> { }
    #endregion

    #region Priority
    [PXDBInt()]
    [PXUIField(DisplayName = "Priority")]
    public virtual int? Priority { get; set; }
    public abstract class priority : PX.Data.BQL.BqlInt.Field<priority> { }
    #endregion

  }
}

Graph : 
 

using System;
using System.Collections;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using PX.Data;
using PX.Data.BQL.Fluent;

namespace EMPPlanningToolR4N5
{
    public class PTFillerReelWidthListMaint : PXGraph<PTFillerReelWidthListMaint>
    {
        public SelectFrom<PTFillerReelWidths>.View FillerReelWidthView;

        public SelectFrom<PTFillerReelWidthSummary>.View FillerReelWidthSummaryView;

        public PXFilter<PTFillerReelWidthsFilter> ReelWidthFilter;

        public PXFilter<PTFillerReelWidthsFilter> ReelWidthSummaryFilter;

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

        public PTFillerReelWidthListMaint()
        {
            FillerReelWidthSummaryView.AllowDelete = false;
            FillerReelWidthSummaryView.AllowInsert = false;
        }
        public IEnumerable fillerReelWidthSummaryView()
        {
            var query = SelectFrom<PTFillerReelWidths>.View.Select(this).RowCast<PTFillerReelWidths>();
            PTFillerReelWidthsFilter filter = ReelWidthSummaryFilter.Current;
            PXTrace.WriteInformation($"Filter : {filter.Gsm}, {filter.PaperTypeID}");

            if (!string.IsNullOrEmpty(filter?.PaperTypeID))
            {
                query = query.Where(x => x.PaperTypeID == filter.PaperTypeID);
            }
            if (filter?.Gsm != null)
            {
                query = query.Where(x => x.Gsm == filter.Gsm);
            }

                query = query.ToList();

            var groupedData = query
                .GroupBy(x => new { x.PaperTypeID, x.Gsm })
                .Select(g => new PTFillerReelWidthSummary
                {
                    PaperTypeID = g.Key.PaperTypeID,
                    Gsm = g.Key.Gsm,
                    WidthCount = g.Count()
                }).ToList();
            return groupedData;
        }

        public IEnumerable fillerReelWidthView()
        {
            var query = SelectFrom<PTFillerReelWidths>.View.Select(this).RowCast<PTFillerReelWidths>();
            PTFillerReelWidthsFilter filter = ReelWidthFilter.Current;
            PXTrace.WriteInformation($"Filter : {filter.Gsm}, {filter.PaperTypeID}");

            if (!string.IsNullOrEmpty(filter?.PaperTypeID))
            {
                query = query.Where(x => x.PaperTypeID == filter.PaperTypeID);
            }
            if (filter?.Gsm != null)
            {
                query = query.Where(x => x.Gsm == filter.Gsm);
            }

            return query.ToList();
        }
    }


    [PXHidden]
    public class PTFillerReelWidthsFilter : IBqlTable
    {
        #region PaperTypeID
        [PXString]
        [PXUIField(DisplayName = "Paper Type ID")]
        [PXSelector(typeof(PTPaperTypes.paperTypeID),
                typeof(PTPaperTypes.paperTypeID),
                typeof(PTPaperTypes.paperTypeCD),
                SubstituteKey = typeof(PTPaperTypes.paperTypeID),
                DescriptionField = typeof(PTPaperTypes.description)
                )]
        public virtual string PaperTypeID { get; set; }
        public abstract class paperTypeID : PX.Data.BQL.BqlString.Field<paperTypeID> { }
        #endregion

        #region Gsm
        [PXInt]
        [PXUIField(DisplayName = "Gsm")]
        [PXSelector(typeof(PTFillerReelGSMs.gsm),
            typeof(PTFillerReelGSMs.gsm)
            )]
        public virtual int? Gsm { get; set; }
        public abstract class gsm : PX.Data.BQL.BqlInt.Field<gsm> { }
        #endregion
    }
}

 

11 replies

Forum|alt.badge.img+1
  • Author
  • Varsity II
  • 57 replies
  • February 17, 2025

Note : 
This resolves when I add [PXDefault()] for all the three fields which I have use in primary key. but I can’t set default values because these are user enterable fields. I need to keep them empty at the beginning.


Keith Richardson
Semi-Pro I
Forum|alt.badge.img+2

PXDefault without any parameters makes it a required field. If you remove the default values, they will set as required. You can remove the (0) from [PXDefault(0)] and it will force it to be required/entered, rather than start with 0.


Forum|alt.badge.img+1
  • Author
  • Varsity II
  • 57 replies
  • February 18, 2025

Hi ​@Keith Richardson,
I initially did not use PXDefault. In that scenario I got this null value error. when I add  PXDefault(0) and 

PXDefault(“##”) for these fields it didn’t triggers that error. I need to avoid that error without adding PXDefault.


Nilkanth Dipak
Semi-Pro I
Forum|alt.badge.img+10

Hi ​@PDharmasena10,

Could you confirm below?

Have you set the InitNewRow on the grid to ‘true’ from Customization editor?

Hope, it helps!
 


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

I believe you either need to set CommitChanges=true on at least one of the fields or set InitNewRow=true (like ​@Nilkanth Dipak suggested). Using a composite key (from multiple fields) can be really tricky in a grid, and this seems to make all the difference.


Forum|alt.badge.img+1
  • Author
  • Varsity II
  • 57 replies
  • February 19, 2025

Hi ​@darylbowman and ​@Nilkanth Dipak,
I tried with changing InitNewRow to true and False. and I make the commitChanges  = true in PaperTypeID field. but the Problem is same.

This First row is added automatically. even I delete it, it appears again when refresh the page.

I tird to delete it and save. it gives following error. “Another process has added the 'PTFillerReelWidths' record. Your changes will be lost. error in Acumatica”

Now i Removed PXDefalt attirbutes from the three fields. Then I able to Save new recode manually. But above problem is still there. Due to that the filter is not working.


Forum|alt.badge.img+8
  • Captain II
  • 366 replies
  • February 19, 2025

@PDharmasena10 

darylbowman wrote:

set CommitChanges=true on at least one of the fields

Have you tried to set CommitChanges=true on more than one of the fields?

 


Forum|alt.badge.img+1
  • Author
  • Varsity II
  • 57 replies
  • February 19, 2025

@aiwan 
In the grid I have only set commitChanges = true only for PaperTypeID field. In the Form which is use for filter, I enable commitChanges for two fields. But it is a seperate DAC and seperate View. (public PXFilter<PTFillerReelWidthsFilter> ReelWidthFilter;)


Forum|alt.badge.img+8
  • Captain II
  • 366 replies
  • February 19, 2025

@PDharmasena10 

 

Setting commitchanges=true for your key fields in the grid may be a good idea.


Forum|alt.badge.img+1
  • Author
  • Varsity II
  • 57 replies
  • February 19, 2025

@aiwan 
I did so. but still have that error.


Forum|alt.badge.img
  • Varsity I
  • 71 replies
  • February 21, 2025

Hi PDharmasena,

 

Have read the above and can’t see anything obvious  in the code not already covered.  A few suggestions though:

  1. Have you checked that the structure of the PTFillerReelsWidths table in the database exactly matches the DAC (for instance if the DAC says a field is primary it actually is in the database,...)
  2. At the start of the post you say you get the error sometimes.  So this means it’s an intermittent issue?  Have you identified the sequence of steps you take to trigger the problem.

Also, if your using SQL server as the backend database, then sometimes using the SQLServerProfiler (under the tools menu) can give you a few clues.  If you haven’t used this before it allows you to monitor exactly what SQL statements Acumatica is attempting to run.  The error message suggests that Acumatica is attempting to run a statement that the database doesn’t like.

John.

 

 


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