Here is what I have so far. Although VS Code is complaining that Reference 'Salesperson Code' in application object 'Sales Header' does not exist. Seems to be there when I look...lol. That error is apparently due to that filter calling the local procedure. When I substitute the local procedure call with a real salesperson code everything is fine.
/// <summary>
/// Table DCH Sales Orders Cue (ID 60010).
/// </summary>
table 60010 "DCH Sales Orders Cue"
{
DataClassification = ToBeClassified;
fields
{
field(1; PrimaryKey; Code[250])
{
DataClassification = ToBeClassified;
}
field(2; SalesInvoicesOpen; Integer)
{
FieldClass = FlowField;
CalcFormula = count("Sales Header" where("Document Type" = Filter(Order), Status = FILTER(Open), "Salesperson Code" = Filter(GetSalespersonCode)));
}
}
keys
{
key(PK; PrimaryKey)
{
Clustered = true;
}
}
local procedure GetSalespersonCode(): Code[20]
var
UserSetup: Record "User Setup";
UserId: Text;
Salesperson: Code[20];
begin
UserId := Database.UserId;
UserSetup.Reset();
UserSetup.SetFilter("User ID", '=%1', UserId);
if UserSetup.FindFirst() then
Salesperson := UserSetup."Salespers./Purch. Code";
exit(Salesperson);
end;
}