Solved

How do I get access to another cache inside a FieldUpdated handler?

  • 4 January 2023
  • 7 replies
  • 470 views

Userlevel 6
Badge +3

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
        [Customer]
        [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.

icon

Best answer by aaghaei 4 January 2023, 08:40

View original

7 replies

Userlevel 7
Badge

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

Userlevel 3
Badge

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

You can use  PXCache cache =  Base.Caches[typeof(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)

 

Userlevel 7
Badge +8

@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.

Userlevel 6
Badge +3

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…

 

Userlevel 6
Badge +3

@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!

Userlevel 6
Badge +3

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

You can use  PXCache cache =  Base.Caches[typeof(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!

Userlevel 7
Badge

LOL @joe21 - I have adjusted 😀

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved