Arsiadi
Arsiadi

Reputation: 39

Acumatica Requisition Total Cost Custom Calculation

I've added three custom decimal? field on Requisition master (RQ302000) and need to prorate the total value of those three fields to the each Requisition line using line base total cost/master total cost ratio and displayed the result as Additional Cost (also custom decimal? field) of each line. This calculation should be triggered when those three new field are updated.

What I don't understand are:
1. What events should be modify related to this needs
2. If it is event on master field, how to get value from line extension field
3. If it is event on line field, how to get value from master extension field

Requisition Custom Screen

Upvotes: 0

Views: 243

Answers (1)

RuslanDev
RuslanDev

Reputation: 6778

1. "What events should be modify related to this needs?"

In a scenario, like yours, one should use combination of RowInserted, RowUpdated and RowDeleted handlers:

The RowInserted event handler is used to implement the business logic for:

  • Inserting the detail data records in a one-to-many relationship.
  • Updating the master data record in a many-to-one relationship.
  • Inserting or updating the related data record in a one-to-one relationship.

The RowUpdated event handler is used to implement the business logic of:

  • Updating the master data record in a many-to-one relationship.
  • Inserting or updating the detail data records in a one-to-many relationship.
  • Updating the related data record in a one-to-one relationship.

The RowDeleted event handler is used to implement the business logic of:

  • Deleting the detail data records in a one-to-many relationship.
  • Updating the master data record in a many-to-one relationship.
  • Deleting or updating the related data record in a one-to-one relationship.

Also FieldUpdated handlers be considered for your scenario:

The FieldUpdated event handler is used to implement the business logic associated with changes to the value of the DAC field in the following cases:

  • Assigning the related fields of the data record containing the modified field their default values or updating them
  • Updating any of the following:
    • The detail data records in a one-to-many relationship
    • The related data records in a one-to-one relationship
    • The master data records in a many-to-one relationship

Refer to API Reference in Help -> Acumatica Framework -> API Reference -> Event Model and T200 developer class for additional information and examples on Acumatica Framework event model.

2. "If it is event on master field, how to get value from line extension field?"

In Acumatica custom fields are declared via DAC extensions. To access the DAC extension object, you can use the following methods:

  1. The GetExtension() generic method available for each DAC instance:

    ContactExt contactExt = curLead.GetExtension<ContactExt>();
    
  2. The GetExtension(object) generic method declared within the non-generic PXCache class

    ContactExt contactExt = Base.LeadCurrent.Cache.GetExtension<ContactExt>(curLead);
    

    or

    ContactExt contactExt = Base.Caches[typeof(Contact)].GetExtension<ContactExt>(curLead);
    
  3. The GetExtension(object) static generic method of the PXCache generic class

    ContactExt contactExt = PXCache<Contact>.GetExtension<ContactExt>(curLead);
    

To get value from line extension field, you should first select records from the Lines data view, then use one of the methods described above to access instance of DAC extension class, for instance:

foreach(RQRequisitionLine line in Base.Lines.Select())
{
    RQRequisitionLineExt lineExt = line.GetExtension<RQRequisitionLineExt>();
}

3. "If it is event on line field, how to get value from master extension field"

That's an easy one: same 3 approaches described above, this time applied to Current property of the primary Document data view, for instance:

Base.Document.Current.GetExtension<RQRequisitionExt>();

Upvotes: 1

Related Questions