In this post I will show you two ways you can create cues in Dynamics 365 Business Central. One calculated by a variable and the other by a flowfield.
For both examples we will show the number of blocked customers in the database. The colour of the cue will also change depending on a predefine threshold.
Variable Calculation
A role center cue is just a page part in which we define a cuegroup.
For this example the ‘BlockedCustomersVar’ will be calculated on the ‘OnAfterGetCurrRecord’ trigger. Also if the number of blocked customer is greater than 2 the cue will change colour. For this first example everything is setup by code.
First, create a page with the ‘PageType’ property set to CardPart. This will allow to embed the page into the rolecenter.
Then, create the variable, calculate it on the ‘OnAfterGetCurrRecord’ trigger and add it to the field.
And last, define the ‘OnDrillDown’ trigger.
See the example below:
The page part can be embeded into the role center just like following:
FlowField Calculation
This method is scalable. It´s based on a setup table (one record table) in which you can define every flowfield you´d like to show as a cue.
In this example the flowfield is calculated as follows.
1. The Base Table
First, create the table with the flowfield. In this case it is ‘BlockedCustomers’:
2. Modify The CardPart
Next to ‘BlockedCustomersVar’ from the first option we just need to show the field. No need to define the ‘OnDrillDown’ trigger as the flowfield let us do the ‘drilling’. Just remember to add the ‘SourceTable’ property to the page:
Find more information about this approach here:
What about the thresholds?
The best part of the flowfield approach is that we can access the cue setup and define our own thresholds for each flowfield on the table. This way every user can have the possibilty to define their own limits.
In order to acces the cue setup we can look for the ‘Cue Setup’ page or add an action to the cue page like the following:
This way when a user defines a threshold via action it will be saved only for this particular user:
Conclusion
Personally, I´d use the variable method for rather more complex algorithms although be aware of the performance. However, if you can define the calculation by a flowfield then a cue table is the way to go.
As you can see in the video below both ways works the same:
Bonus
You can define the ‘CuegroupLayout’ property to ‘wide’ for larger numbers and it will look like the following:
Source code:
table 50103 "CustomCueTable"
{
DataClassification = ToBeClassified;
fields
{
field(1; PrimaryKey; Code[20])
{
NotBlank = true;
DataClassification = ToBeClassified;
}
field(2; BlockedCustomers; Integer)
{
Editable = false;
FieldClass = FlowField;
CalcFormula = count(Customer where(Blocked = filter(All)));
}
}
keys
{
key(PK; PrimaryKey)
{
Clustered = true;
}
}
procedure InsertIfNotExists()
begin
Rec.Reset();
if not Rec.Get() then begin
Rec.Init();
Rec.Insert();
end;
end;
}
page 50113 "CustomCue"
{
PageType = CardPart;
SourceTable = CustomCueTable;
RefreshOnActivate = true;
layout
{
area(Content)
{
cuegroup(cuegroup1)
{
Caption = 'Blocked Customers';
field(BlockedCustomers; BlockedCustomersVar)
{
Caption = 'By Variable';
ApplicationArea = all;
StyleExpr = Style;
trigger OnDrillDown()
var
Cust: Record Customer;
CustomerList: Page "Customer List";
begin
Cust.SetRange(Blocked, Cust.Blocked::All);
CustomerList.SetTableView(Cust);
CustomerList.Run();
end;
}
field(BlockedCustomersFlowField; Rec.BlockedCustomers)
{
Caption = 'By FlowField';
ApplicationArea = all;
}
}
}
}
actions
{
area(Processing)
{
action("Set Up Cues")
{
ApplicationArea = All;
Image = Setup;
trigger OnAction()
var
CuesAndKpis: Codeunit "Cues And KPIs";
CueRecordRef: RecordRef;
begin
CueRecordRef.GetTable(Rec);
CuesAndKpis.OpenCustomizePageForCurrentUser(CueRecordRef.Number);
end;
}
}
}
trigger OnOpenPage()
begin
Rec.InsertIfNotExists();
end;
trigger OnAfterGetCurrRecord()
var
Cust: Record Customer;
begin
Cust.SetRange(Blocked, Cust.Blocked::All);
BlockedCustomersVar := Cust.Count();
if BlockedCustomersVar > 2 then
Style := 'Unfavorable';
end;
var
BlockedCustomersVar: Integer;
Style: Text;
}
Hope you find it useful.
Check this other article on how to boost performance in Business Central.
My Requirement is to create Cue for “Remaining Amt (LCY)” field in Customer Ledger Entry Table for Invoice with one particular fiscal year (say april 22 – march 23). Since it is the flowfield I used the code as
FieldClass = FlowField;
CalcFormula = Sum(“Detailed Cust. Ledg. Entry”.”Amount (LCY)” where(“Document Type” = filter(Invoice), “Posting Date” = filter(‘-1Y’ .. ‘CD’)));
But if I run the code, the value in the cue doesn’t match with the total sum of Remaining Amt (LCY) field with filter (Invoice and current year).
As in reference If I try to use the code as
Sum(“Detailed Cust. Ledg. Entry”.”Amount (LCY)” WHERE (Cust. Ledger Entry No.=FIELD(Entry No.),Posting Date=FIELD(Date Filter)))
In my VS Code, I get error to use the above filter as Cust. Ledger Entry No.=FIELD(Entry No.). I cannot able to get correct filter to get exact value in the cue. Could you please tell me how to proceed with the filter to get the correct value in the Cues?
Hi, you should try to also filter ‘Exclude from calculation’. Which is how the standard ‘Remaining Amount’ flowfield works.
If that doesn´t work, you will need to develop the calculation by code and not by using a flowfield.
How to use “Exclude from calculation” in code?
For eg. in my code I use filters like document type and posting group as “Document Type” = filter(Invoice), “Posting Date” = filter(‘-1Y’ .. ‘CD’)).
In the same way how to use “Exclude from calculation” in filter part in my code?
Sure, “Excluded from calculation” = CONST(false).
Let me know if that worked.
If I use the above filter in my code as:
CalcFormula = Sum(“Detailed Cust. Ledg. Entry”.”Amount (LCY)” where( “Excluded from calculation” = CONST(false), “Document Type” = filter(Invoice), “Posting Date” = filter(‘-1Y’ .. ‘CD’)));
I get following error as “Reference ‘Excluded from calculation’ in application object ‘Detailed Cust. Ledg. Entry’ does not exist”.
My Requirement is to create Cue for “Remaining Amt (LCY)” field in Customer Ledger Entry Table for Invoice with one particular fiscal year (say april 22 – march 23). Since it is the flowfield I used the code as
FieldClass = FlowField;
CalcFormula = Sum(“Detailed Cust. Ledg. Entry”.”Amount (LCY)” where(“Document Type” = filter(Invoice), “Posting Date” = filter(‘-1Y’ .. ‘CD’)));
But if I run the code, the value in the cue doesn’t match with the total sum of Remaining Amt (LCY) field with filter (Invoice and current year).
As in reference If I try to use the code as
Sum(“Detailed Cust. Ledg. Entry”.”Amount (LCY)” WHERE (Cust. Ledger Entry No.=FIELD(Entry No.),Posting Date=FIELD(Date Filter)))
In my VS Code, I get error to use the above filter as Cust. Ledger Entry No.=FIELD(Entry No.). I cannot able to get correct filter to get exact value in the cue. Could you please tell me how to proceed with the filter to get the correct value in the Cues?
Just try BeyondCues from Appsource, you can create as many Cues as you need.
Thanks for the suggestion, will give it a try!