saikiran
saikiran

Reputation: 75

Calculate field value by PXformula attribute in Acumatica

I am using pxformula to multiply values but failed to get it. when i multiplied constant values like decimal100* decimal100, it gave me result. but when I use avgcost, it is not working. I think avgcost used in pxformula is coming from INItemCost table. Below is the article I got from acumatica.

You can use the predefined attributes PXFormula and PXUnboundFormula in data access classes (DACs) to calculate field values from the values of the same data record. You can also calculate aggregated values over detail data records and assign an aggregated value to a field of the master data record.

enter image description here

Screenshot shows no result rendered. enter image description here

Please advise me to make work out this.

Upvotes: 0

Views: 1699

Answers (1)

Fernando
Fernando

Reputation: 433

In this case, you are looking to update values from the DAC CSAnswer with information from the DAC INItemCost. It is my understanding that PXFormula[] attribute can be used to update values from the same DAC record, and/or for aggregated calculation.

Typical example: A grid's Unit Price and Quantity are used to obtained Extended Price (values from the same DAC record). And that result is updated in the document's total (aggregated total) I have not seen it being used in an example like yours.

I was able however, to update the value with this alternative approach:

  public class InventoryItemMaint_Extension : PXGraphExtension<InventoryItemMaint>
  {  
       protected virtual void CSAnswers_Value_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
       {
           if (e.Row == null) return;

          CSAnswers answer = (CSAnswers)e.Row;
          CSAnswersExt answerExt = sender.GetExtension<CSAnswersExt>(answer);

          if (answerExt != null)
          {

              INItemCost itemCost = PXSelect<INItemCost, Where<INItemCost.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(this.Base, this.Base.Item.Current.InventoryID);

              if (itemCost != null && itemCost.AvgCost != null)
              {
                  answerExt.UsrPrice = itemCost.AvgCost * (decimal)365;
              }
          }
        }
    }

Result

enter image description here

Additional notes

  • I used the CSAnswers_Value field to update the data given that average cost is a disabled field
  • This logic will update UsrPrice in new records and for the specific attribute rows being updated. If you are looking to update existing data in bulk, you will have to use additional logic.

Upvotes: 2

Related Questions