Skip to main content
Solved

Setting a field to null fires in the code but the date still gets filled in

  • September 10, 2021
  • 4 replies
  • 464 views

Joe Schmucker
Captain II
Forum|alt.badge.img+2

I am working on the Task screen (CR306020).  I am able to set the Start Date to null so that the user must select a Start Date.  I want to also default the Due Date to null.

Here is my code:

    public class CRTaskMaint_Extension : PXGraphExtension<CRTaskMaint>
    {
        #region Event Handlers

        protected void CRActivity_RowInserting(PXCache cache, PXRowInsertingEventArgs e)
        {
            var row = (CRActivity)e.Row;
            //var dateAndTime = DateTime.Now;
            //var date = dateAndTime.Date.AddDays(1);
            row.StartDate = null;
            row.Priority = null;
            row.UIStatus = null;
        }

        protected void _(Events.FieldUpdated<CRActivity, CRActivity.startDate> e)
        {
            var row = (CRActivity)e.Row;
            row.EndDate = null;
        }

        #endregion
    }

The RowInserting works great.  The Start Date is empty after this code fires.

The FieldUpdated event fires.  I verified that the EndDate is being set to null.  But when the screen is updated, it shows the Start Date + 1 day.  This appears to be a default I cannot override.

I noted that the actual field name is EndDate_Date on the screen. In the editor, when you click on the Due Date field

 

You get this in the properties

 

I don’t know if what is going on behind the scenes to populate this field by Acumatica.

I looked in the CRTaskMaint.cs in the Acumatica repository and I don’t see any code there that sets any defaults for this field.  

This seems like it should be simple, but as usual, it is the simple changes that cause me so much grief.

Any help is greatly appreciated.

Joe Schmucker

Best answer by Naveen Boga

Hi Joe,

Just to inform you that there is no code in CRTaskMaint related to “EndDate” field.

This value is updating in RowUpdated Event, this code is available inside the EPEndDateAttribute. Please find the screenshot for reference. As soon as Start Date is updated then EndDate will updated using RowUpdated event code.

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

4 replies

Kulvir Kaila
Jr Varsity I
Forum|alt.badge.img+1
  • Jr Varsity I
  • 61 replies
  • September 10, 2021

I believe you need to look at the EPStartDateAttribute and the associated FieldUpdating event to see the behavior.  You might need to update the DAC for the StartDate field if you want to change the default behavior.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3417 replies
  • Answer
  • September 10, 2021

Hi Joe,

Just to inform you that there is no code in CRTaskMaint related to “EndDate” field.

This value is updating in RowUpdated Event, this code is available inside the EPEndDateAttribute. Please find the screenshot for reference. As soon as Start Date is updated then EndDate will updated using RowUpdated event code.


Joe Schmucker
Captain II
Forum|alt.badge.img+2
  • Author
  • Captain II
  • 458 replies
  • September 13, 2021

When I go to customize the Task screen, I inspect the element and it shows it is part of CRTaksMaint, not anything to do with EPTaskEnq.  I don’t know how to create the Visual Studio code to add a customized row updated handler for this.  I am not too good at this and I don’t know how to setup the Class signature for the EPTaskEnq graph.  I normally use Acumatica to create the code in the project editor and then send it over to Visual Studio. 

 

I found another piece of code from another developer

I tried putting this code in this class.  The event doesn’t fire in Debug mode. 

I would like to know how I would have generated this from Acumatica.  By using the inspector on the Acumatica site, I don’t see anything to reference EPTaskEnq?

 

In the Acumatica project editor, I tried to override the Attribute on EndDate (shows as Due Date in the editor, but the Field Name is EndDate

 

I get this error.

This “tiny” edit has turned out to be a lot harder than I thought it would.

 

 


Joe Schmucker
Captain II
Forum|alt.badge.img+2
  • Author
  • Captain II
  • 458 replies
  • September 13, 2021

Thanks all for your inputs.  This is working now.  If the StartDate is updated, it sets the EndDate to null.  Seems to be doing the trick.

        protected void _(Events.RowUpdated<CRActivity> e)
        {
            if (!e.Cache.ObjectsEqual<CRActivity.startDate>(e.Row, e.OldRow))
            {
                e.Row.EndDate = null;
            }
        }

I found the Cache.ObjectsEqual in the Acumatica training.  Thank God for the Acumatica training code.  


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