Skip to main content
Answer

DAC Extension fields Default value insert issue

  • August 1, 2022
  • 8 replies
  • 361 views

Forum|alt.badge.img

Hi Everyone,

I’ve Created a new Extension DAC.in this DAC fields , I have to set the PXDefault values but, getting  null reference error when inserting time.

can you please help me on this ,

How to insert the Default value in DB? .

 

this is my Extension DAC fields :-

 

#region WcID

        [WorkCenterIDField(Enabled = false)]

        [PXUIField(DisplayName = "Work Center", Enabled = false)]

        [PXDefault(typeof(Search<AMProdOper.wcID,

          Where<AMProdOper.orderType, Equal<Current<AMClockItem.orderType>>,

              And<AMProdOper.prodOrdID, Equal<Current<AMClockItem.prodOrdID>>,

              And<AMProdOper.operationID, Equal<Current<AMClockItem.operationID>>>>>>))]

        [PXFormula(typeof(Default<AMClockItem.operationID>))]

        [PXReferentialIntegrityCheck]

        public abstract class wcID : PX.Data.BQL.BqlString.Field<wcID> { }

        protected string _WcID;

        public virtual string WcID

        {

            get

            {

                return this._WcID;

            }

            set

            {

                this._WcID = value;

            }

        }

        #endregion

        #region AllowMultiClockEntry

        [PXDBBool]

        [PXUIField(DisplayName = "Allow Clock Entry for Multiple Production Orders", Enabled = false, Visible = false)]

        [PXDefault(typeof(Search<AMWCExt.allowMultiClockEntry,

          Where<AMWC.wcID, Equal<Current<wcID>>>>))]

        [PXFormula(typeof(Default<wcID>))]

        [PXReferentialIntegrityCheck]

        public abstract class allowMultiClockEntry : PX.Data.BQL.BqlBool.Field<allowMultiClockEntry> { }

        protected bool? _AllowMultiClockEntry;

        public virtual bool? AllowMultiClockEntry

        {

            get

            {

                return this._AllowMultiClockEntry;

            }

            set

            {

                this._AllowMultiClockEntry = value;

            }

        }

        #endregion

        #region LaborTimeSeconds

        [PXDBInt]

        [PXUIField(DisplayName = "Labor Time Seconds", Enabled = false, Visible = false)]

        [PXDefault(0)]

        public abstract class laborTimeSeconds : PX.Data.BQL.BqlInt.Field<laborTimeSeconds> { }

        protected int? _LaborTimeSeconds;

        public virtual int? LaborTimeSeconds

        {

            get

            {

                return this._LaborTimeSeconds;

            }

            set

            {

                this._LaborTimeSeconds = value;

            }

        }

        #endregion

Best answer by Marco Villasenor

I reviewed your code and I found the attributes are in the wrong place. They should be modifying the property getter/setter and not the class. That's why they are not working.

It was easy to miss as @Naveen Boga  and I didn’t see it the first time 😅.

Try it like this:

#region WcID


public abstract class wcID : PX.Data.BQL.BqlString.Field<wcID> { }

[WorkCenterIDField(Enabled = false)]
[PXUIField(DisplayName = "Work Center", Enabled = false)]
[PXDefault(typeof(Search<AMProdOper.wcID,
Where<AMProdOper.orderType, Equal<Current<AMClockItem.orderType>>,

And<AMProdOper.prodOrdID, Equal<Current<AMClockItem.prodOrdID>>,

And<AMProdOper.operationID, Equal<Current<AMClockItem.operationID>>>>>>))]
[PXFormula(typeof(Default<AMClockItem.operationID>))]
[PXReferentialIntegrityCheck]
public virtual string WcID { get; set; }

#endregion

#region AllowMultiClockEntry

public abstract class allowMultiClockEntry : PX.Data.BQL.BqlBool.Field<allowMultiClockEntry> { }

[PXDBBool]
[PXUIField(DisplayName = "Allow Clock Entry for Multiple Production Orders", Enabled = false, Visible = false)]
[PXDefault(typeof(Search<AMWCExt.allowMultiClockEntry,
Where<AMWC.wcID, Equal<Current<wcID>>>>))]
[PXFormula(typeof(Default<wcID>))]
[PXReferentialIntegrityCheck]
public virtual bool? AllowMultiClockEntry { get; set; }

#endregion

#region LaborTimeSeconds

public abstract class laborTimeSeconds : PX.Data.BQL.BqlInt.Field<laborTimeSeconds> { }

[PXDBInt]
[PXUIField(DisplayName = "Labor Time Seconds", Enabled = false, Visible = false)]
[PXDefault(0)]
public virtual int? LaborTimeSeconds { get; set; }

#endregion

 

8 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • August 1, 2022

Hi, @NageswaraRaoAddanki60  This is related to data issue and the above code provided looks good.

 

Just for verification, you can write this code in the FieldDefaulting event and debug whether you are getting the values or not to identify the issue.


Forum|alt.badge.img

Hi @Naveen Boga I’m Try to debugging this event. debug it is not hitting.

 

 protected void AMClockTran_WcID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)

        {

            var row = (AMClockTran)e.Row;

        }


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • August 1, 2022

Hi @NageswaraRaoAddanki60  This will invoke only for the first of the document creation and also, make sure that the field should have commitechanges = true in the .aspx page.


Forum|alt.badge.img

Hello @Naveen Boga 

Checking one field value that is AMClockExt.wcID in this value getting null value in FieldDefaulting Event.

 


Marco Villasenor
Jr Varsity II
Forum|alt.badge.img+2

Could you try setting PXDefault to a fixed value to confirm the default value is being set?

Since you use a Search to set the value, it could be setting null because it doesn’t find a value:

[PXDefault(typeof(Search<AMProdOper.wcID,
Where<AMProdOper.orderType, Equal<Current<AMClockItem.orderType>>,
And<AMProdOper.prodOrdID, Equal<Current<AMClockItem.prodOrdID>>,
And<AMProdOper.operationID, Equal<Current<AMClockItem.operationID>>>>>>))]

 


Forum|alt.badge.img

Hi @Marco Villasenor I’m Already Added like you. The Main aim is PXDefault value not Setting to Extension DAC fields, the total Extension DAC fields still showing null values. This DAC fields are not null fields in DB Side. So, whenever inserting data Getting null Exception.


Marco Villasenor
Jr Varsity II
Forum|alt.badge.img+2

I reviewed your code and I found the attributes are in the wrong place. They should be modifying the property getter/setter and not the class. That's why they are not working.

It was easy to miss as @Naveen Boga  and I didn’t see it the first time 😅.

Try it like this:

#region WcID


public abstract class wcID : PX.Data.BQL.BqlString.Field<wcID> { }

[WorkCenterIDField(Enabled = false)]
[PXUIField(DisplayName = "Work Center", Enabled = false)]
[PXDefault(typeof(Search<AMProdOper.wcID,
Where<AMProdOper.orderType, Equal<Current<AMClockItem.orderType>>,

And<AMProdOper.prodOrdID, Equal<Current<AMClockItem.prodOrdID>>,

And<AMProdOper.operationID, Equal<Current<AMClockItem.operationID>>>>>>))]
[PXFormula(typeof(Default<AMClockItem.operationID>))]
[PXReferentialIntegrityCheck]
public virtual string WcID { get; set; }

#endregion

#region AllowMultiClockEntry

public abstract class allowMultiClockEntry : PX.Data.BQL.BqlBool.Field<allowMultiClockEntry> { }

[PXDBBool]
[PXUIField(DisplayName = "Allow Clock Entry for Multiple Production Orders", Enabled = false, Visible = false)]
[PXDefault(typeof(Search<AMWCExt.allowMultiClockEntry,
Where<AMWC.wcID, Equal<Current<wcID>>>>))]
[PXFormula(typeof(Default<wcID>))]
[PXReferentialIntegrityCheck]
public virtual bool? AllowMultiClockEntry { get; set; }

#endregion

#region LaborTimeSeconds

public abstract class laborTimeSeconds : PX.Data.BQL.BqlInt.Field<laborTimeSeconds> { }

[PXDBInt]
[PXUIField(DisplayName = "Labor Time Seconds", Enabled = false, Visible = false)]
[PXDefault(0)]
public virtual int? LaborTimeSeconds { get; set; }

#endregion

 


Marco Villasenor
Jr Varsity II
Forum|alt.badge.img+2

Hi @NageswaraRaoAddanki60 Did it work?