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:

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-cues-action-tiles


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.


2 Ways To Create Cues In Business Central

Post navigation


Leave a Reply

Your email address will not be published. Required fields are marked *