Skip to main content
Solved

add row to grid

  • December 24, 2025
  • 1 reply
  • 15 views

Forum|alt.badge.img+2

When add row to grid have error:
Object reference not set to an instance of an object.


View:
[PXCopyPasteHiddenView]
        [PXViewName(Messages.WorkOrders)]
        public PXSelect<AMProdWorkOrder,
           Where<AMProdWorkOrder.orderType, Equal<Current<AMProdItem.orderType>>,
               And<AMProdWorkOrder.prodOrdID, Equal<Current<AMProdItem.prodOrdID>>>>>
           WorkOrders;

 var wo = new AMProdWorkOrder
                {
                    OrderType = prodItem.OrderType,
                    ProdOrdID = prodItem.ProdOrdID,
                    NbrUI = nbrUI,
                    SubWorkOrder = $"{prodItem.ProductOrdID}-{nbrUI}",
                    Date = dateRow.Date,
                    WcID = dateRow.WcID,
                    Capacity = dateRow.Capacity,
                    PlanQty = dateRow.PlanQty
                };

                wo = WorkOrders.Insert(wo);


DAC:
    [Serializable]
    [PXCacheName(Messages.ProdWorkOrder)]
    public class AMProdWorkOrder : PXBqlTable, IBqlTable
    {
        #region OrderType
        public abstract class orderType : PX.Data.BQL.BqlString.Field<orderType> { }

        [PXDefault(typeof(AMProdItem.orderType))]
        [AMOrderTypeField(IsKey = true, Visibility = PXUIVisibility.SelectorVisible)]
        [PXRestrictor(typeof(Where<AMOrderType.active, Equal<True>>), PX.Objects.SO.Messages.OrderTypeInactive)]
        [AMOrderTypeSelector]
        public virtual String OrderType { get; set; }
        #endregion

        #region ProdOrdID
        public abstract class prodOrdID : PX.Data.BQL.BqlString.Field<prodOrdID> { }

        [ProductionNbr(IsKey = true, Required = true, Visibility = PXUIVisibility.SelectorVisible)]
        [ProductionOrderSelector(typeof(AMProdItem.orderType), true)]
        [PXDBDefault(typeof(AMProdItem.prodOrdID), DefaultForUpdate = false, FieldUpdateMode = PXFieldUpdateMode.OnParentPersisted)]
        [PXParent(typeof(SelectFrom<AMProdItem>
            .Where<AMProdItem.prodOrdID.IsEqual<AMProdItem.prodOrdID.FromCurrent>.
                And<AMProdItem.orderType.IsEqual<AMProdItem.orderType.FromCurrent>>>))]
        public virtual String ProdOrdID { get; set; }
        #endregion

        #region LineNbr
        public abstract class lineNbr : PX.Data.BQL.BqlInt.Field<lineNbr> { }
        [PXDBInt()]
        [PXUIField(DisplayName = Messages.LineNbr, Visible = false, Enabled = false)]
        [PXLineNbr(typeof(AMProdItemExt.usrLineCntrWO))]
        public virtual int? LineNbr { get; set; }
        #endregion

        #region NbrUI
        public abstract class nbrUI : PX.Data.BQL.BqlInt.Field<nbrUI> { }
        [PXInt()]
        [PXUIField(DisplayName = Messages.NbrUI, Visible = true, Enabled = false)]
        public virtual int? NbrUI { get; set; }
        #endregion

        #region SubWorkOrder
        public abstract class subWorkOrder : PX.Data.BQL.BqlString.Field<subWorkOrder> { }
        [PXDBString(25, IsUnicode = true)]
        [PXUIField(DisplayName = Messages.SubWorkOrder, Enabled = false)]
        public virtual String SubWorkOrder { get; set; }
        #endregion

        #region Date
        public abstract class date : PX.Data.BQL.BqlDateTime.Field<date> { }
        [PXDate(UseTimeZone = false)]
        [PXUIField(DisplayName = Messages.Date, Enabled = false)]
        public virtual DateTime? Date { get; set; }
        #endregion

        #region WcID
        public abstract class wcID : PX.Data.BQL.BqlString.Field<wcID> { }
        [WorkCenterIDField(Visibility = PXUIVisibility.SelectorVisible, DisplayName = Messages.Line, Required = false, Enabled = false)]
        [PXDefault()]
        [PXSelector(typeof(Search2<AMWC.wcID,
            InnerJoin<INSite, On<INSite.siteID, Equal<AMWC.siteID>>>,
            Where<Match<INSite, Current<AccessInfo.userName>>>>), DescriptionField = typeof(AMWC.descr))]
        [PXForeignReference(typeof(Field<AMProdWorkOrder.wcID>.IsRelatedTo<AMWC.wcID>))]
        [PXRestrictor(typeof(Where<AMWC.activeFlg, Equal<True>>), Messages.WorkCenterNotActive)]
        public virtual String WcID { get; set; }
        #endregion

        #region Capacity
        public abstract class capacity : PX.Data.BQL.BqlDecimal.Field<capacity> { }
        [PXDBQuantity(MinValue = 0.0)]
        [PXDefault(TypeCode.Decimal, "0.0", PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = Messages.Capacity, Enabled = false)]
        public virtual Decimal? Capacity { get; set; }
        #endregion

        #region PlanQty
        public abstract class planQty : PX.Data.BQL.BqlDecimal.Field<planQty> { }
        [PXDBQuantity(MinValue = 0.0)]
        [PXDefault(TypeCode.Decimal, "0.0", PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = Messages.PlanQty, Enabled = false)]
        public virtual Decimal? PlanQty { get; set; }
        #endregion

        #region CreatedByID
        [PXDBCreatedByID()]
        public virtual Guid? CreatedByID { get; set; }
        public abstract class createdByID : PX.Data.BQL.BqlGuid.Field<createdByID> { }
        #endregion

        #region CreatedByScreenID
        [PXDBCreatedByScreenID()]
        public virtual string CreatedByScreenID { get; set; }
        public abstract class createdByScreenID : PX.Data.BQL.BqlString.Field<createdByScreenID> { }
        #endregion

        #region CreatedDateTime
        [PXDBCreatedDateTime()]
        public virtual DateTime? CreatedDateTime { get; set; }
        public abstract class createdDateTime : PX.Data.BQL.BqlDateTime.Field<createdDateTime> { }
        #endregion

        #region LastModifiedByID
        [PXDBLastModifiedByID()]
        public virtual Guid? LastModifiedByID { get; set; }
        public abstract class lastModifiedByID : PX.Data.BQL.BqlGuid.Field<lastModifiedByID> { }
        #endregion

        #region LastModifiedByScreenID
        [PXDBLastModifiedByScreenID()]
        public virtual string LastModifiedByScreenID { get; set; }
        public abstract class lastModifiedByScreenID : PX.Data.BQL.BqlString.Field<lastModifiedByScreenID> { }
        #endregion

        #region LastModifiedDateTime
        [PXDBLastModifiedDateTime()]
        public virtual DateTime? LastModifiedDateTime { get; set; }
        public abstract class lastModifiedDateTime : PX.Data.BQL.BqlDateTime.Field<lastModifiedDateTime> { }
        #endregion

        #region Tstamp
        [PXDBTimestamp()]
        [PXUIField()]
        public virtual byte[] Tstamp { get; set; }
        public abstract class tstamp : PX.Data.BQL.BqlByteArray.Field<tstamp> { }
        #endregion

        #region Noteid
        [PXNote()]
        public virtual Guid? Noteid { get; set; }
        public abstract class noteid : PX.Data.BQL.BqlGuid.Field<noteid> { }
        #endregion
    }

 

Best answer by aleksandrsechin

If you can confirm that the prodItem and dateRow variables are not null, then I assume that AMProdItemExt.usrLineCntrWO is a newly added field and currently contains null values in the database. However, PXLineNbr requires a non-null integer value.

Try running the following script and then test again:

update AMProdItem set usrLineCntrWO = 0;

This issue usually occurs for records that were created before the field was added, but not for newly created ones (provided that you added the [PXDefault(0)] attribute to the AMProdItemExt.usrLineCntrWO field).

1 reply

Forum|alt.badge.img+3
  • Jr Varsity I
  • Answer
  • December 24, 2025

If you can confirm that the prodItem and dateRow variables are not null, then I assume that AMProdItemExt.usrLineCntrWO is a newly added field and currently contains null values in the database. However, PXLineNbr requires a non-null integer value.

Try running the following script and then test again:

update AMProdItem set usrLineCntrWO = 0;

This issue usually occurs for records that were created before the field was added, but not for newly created ones (provided that you added the [PXDefault(0)] attribute to the AMProdItemExt.usrLineCntrWO field).