Hello!
I want to add a field to the /Item Invoicing FactBox/ in Business Central. This is the box that appears to the right when clicking on an item in the Items page.
I want this field to show the average amount that item is being sold for. I figured I could add a field to the Item table that gets the average of the /Sales Amount (Actual)/ from the /Item Ledger Entry/ table.
So I tried adding this to my Item table:
field(50103; /Average Sales Amount/; Decimal)
{
CalcFormula = average(/Item Ledger Entry/./Sales Amount (Actual)/ WHERE(/Item No./ = field(/No./)));
Caption = 'Average Sales Amount';
Editable = false;
FieldClass = FlowField;
}
Then I tried adding that field to the field to the /Item Invoicing FactBox/ page like this:
pageextension 50123 ItemInvFactBoxExt extends /Item Invoicing FactBox/
{
layout
{
addlast(content)
{
field(/Average Sales Amount/; Rec./Average Sales Amount/)
{
ApplicationArea = All;
}
}
}
}
But that gives me an error in the FactBox saying:
Error: An unexpected error occurred after a database command was cancelled..
I tried adding another couple of fields from the Item Ledger Entry table, such as /Qty. On Sales Order/ which is quite similar in a way, since it is a CalcFormula sum field from the same table. I am able to add that field, so it seems to me like there is a problem with the /average/ field in this particular case.
How can I get the field I want to show in the FactBox without breaking it?