Skip to main content

EDIT: I wish I could edit the Title for this question...It should be How do I get access to another cache inside a FieldUpdated handler

I added User Defined fields to the Details tab of the Employee Time Card Entry screen EP305000.

The fields pull data from custom maintenance tables.  It is working.

The table that the UDF’s are stored in is the PMTimeActivity table.  That is the table that holds the Details grid data.

The graph extension for the screen is 

    public class TimeCardMaint_Extension : PXGraphExtension<TimeCardMaint>
 

In the extension, I grab the customer ID that is selected using the FieldUpdating handler for the UsrCustomerID field.

My current code can only get the DAC extension for PMTimeActivity if the record has been saved.  I get the reference to the extension using a BQL statement.  I highlighted in red the code that gets the PMTimeActivity extension.

If the row is not saved, tcd will always be null.

namespace PX.Objects.EP
{
    public class TimeCardMaint_Extension : PXGraphExtension<TimeCardMaint>
    {
        #region Event Handlers
        protected void EPTimecardDetail_UsrCustomerID_FieldUpdating(PXCache cache,           PXFieldUpdatingEventArgs e)
        {
            var row = (EPTimecardDetail)e.Row;
            PMTimeActivity tcd = SelectFrom<PMTimeActivity>.Where<PMTimeActivity.noteID.IsEqual<@P.AsGuid>>.View.Select(Base, row.RefNoteID);
            if (tcd == null) return;

 

The cache for this handler shows this: 

The DAC extension that stores the UDF values is

    public class PMTimeActivityExt : PXCacheExtension<PX.Objects.CR.PMTimeActivity>
    {

        #region UsrCustomerID
        eCustomer]
        ÂPXUIField(DisplayName = "Customer")]
        ÂPXRestrictor(typeof(Where<BAccount.parentBAccountID, IsNotNull>), ICSMessages.ParentAccount)]
        public virtual int? UsrCustomerID { get; set; }
        public abstract class usrCustomerID : PX.Data.BQL.BqlInt.Field<usrCustomerID> { }
        #endregion

 

How can I get a reference to the PMTimeActivity DAC extension (cache) inside of this handler?  It HAS to exist or the UDF fields on the screen wouldn’t show the values as they are selected.

Hi @joe21 - I have updated the title for you 😀


Ist Answer: (before I read the question...)

You can use  PXCache cache =  Base.Cachesetypeof(PMTimeActivity)]  to get the cache you need.

Or if there is a View in the Base for <PMTimeActivity> you can simply reference Base.Viewname.Cache

 

2nd Answer - the EPTimecardDetail is a child DAC of PMTimeActivity - so you can use the cache of the event handler and the e.Row to get your extension eg

TimeCardMaint_Extension rowExt = cache.GetExtension<TimeCardMaint_Extension>(row)

 


@joe21

assuming your tcd is returning the expected record, the below code will do the work for you:

PMTimeActivityExt tcd.GetExtension<PMTimeActivityExr>();

PXSelect selects from DB and merges with cache so you have access to data even before saved. PXSelectReadonly retrieves the saved data only.


Hi @joe21 - I have updated the title for you 😀

Hi Chris...I accidentally set your reply as the best answer...Can you remove that too?  HAHAHA!  It’s been a hard couple days here…

 


@aaghaei  Perfect!

PMTimeActivityExt tcd = cache.GetExtension<PMTimeActivityExt>(row);

This is another gem to add to my collection of how to’s.  This was not included in the Acumatica training which I routinely plagiarize.  

THANK YOU ALL!


Ist Answer: (before I read the question...)

You can use  PXCache cache =  Base.Cachesetypeof(PMTimeActivity)]  to get the cache you need.

Or if there is a View in the Base for <PMTimeActivity> you can simply reference Base.Viewname.Cache

 

2nd Answer - the EPTimecardDetail is a child DAC of PMTimeActivity - so you can use the cache of the event handler and the e.Row to get your extension eg

TimeCardMaint_Extension rowExt = cache.GetExtension<TimeCardMaint_Extension>(row)

 

This probably works too...but I was so excited when I saw there was a reply to this topic, I saw @aaghaei  first.  I wish you could both be given best answer.  I accidentally marked Chris’s as best answer.  

I guess Chris needs the pat on the back for all the work he does for us in the forum!


LOL @joe21 - I have adjusted 😀


Reply