Skip to main content
Solved

Retrieve calculated fields from the API

  • January 8, 2025
  • 4 replies
  • 67 views

Hey everyone. 

We have done a customisation where we extended the Opening Balances to the Customer screen. 

Here are the fields in DAC:

 public class MAKLCustomerBalanceSummaryExt : PXCacheExtension<CustomerMaint.CustomerBalanceSummary>
{
#region UsrMAKLCurrentBalance
[PXBaseCury(null, typeof(Customer.baseCuryID))]
[CurySymbol(null, typeof(Customer.baseCuryID), null, null)]
[PXUIField(DisplayName = "Current Balance", Visible = true, Enabled = false)]
public virtual decimal? UsrMAKLCurrentBalance { get; set; }
public abstract class usrMAKLCurrentBalance : BqlType<IBqlDecimal, decimal>.Field<usrMAKLCurrentBalance> { }
#endregion
}

We have then extended this field to the Web Service Endpoint, but it returns 0 every time even though the customer has a balance.

I have then added the RowSelected event handler and populated the field in there as well, but to no avail. 

How can I get this field to display in the Web Service?

 

Best answer by Dmitrii Naumov

@DewaldKC There are couple of things to consider:

  1. RowSelected is not called in Get API requests
  2. If the field is calculated based on other fields in the record, they need to be added to PXDependsOnFields attribute to indicate that the fields need to be retrieved before the calculation

I think usually the best place for such calculation is FieldSelecting event or the view delegate. I think customerBalanceDelegate should be fine here. Not sure what’s wrong with that in your case.

4 replies

jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • January 8, 2025

Hi ​@DewaldKC ,

The API only returns values for bound fields. You are currently using an unbound field, which is why the data is not being retrieved through the endpoint. Please change the field to a bound field and try again.


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • January 8, 2025

@jinin it is not correct. API can return data from unbound fields as well. 

However, it is important how you fill the data in the field.

@DewaldKC could you please share how the field is populated?


  • Author
  • Freshman II
  • January 8, 2025

@jinin - Thanks, I initially thought the same but ​@Dmitrii Naumov is correct, unbound fields can be returned. 

Originally it was updated in the customerBalanceDelegate where I override it but I have since tried the Custer row selected event handler as well. I have debugged it and there is definitely a value returned.

protected void Customer_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
var row = (Customer)e.Row;
if (row == null) { return; }

MAKLCustomerExt rowExt = row.GetExtension<MAKLCustomerExt>();
rowExt.UsrMAKLCurrentBalance = CalcCustomerBalanceToDate(row.BAccountID);

}

 

 


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • Answer
  • January 9, 2025

@DewaldKC There are couple of things to consider:

  1. RowSelected is not called in Get API requests
  2. If the field is calculated based on other fields in the record, they need to be added to PXDependsOnFields attribute to indicate that the fields need to be retrieved before the calculation

I think usually the best place for such calculation is FieldSelecting event or the view delegate. I think customerBalanceDelegate should be fine here. Not sure what’s wrong with that in your case.