This walkthrough demonstrates how to create a Cue that is based on a normal field that derives data from a Microsoft Dynamics NAV query object. The following figure illustrates the Sales This Month Cue that is added by this walkthrough.
Note |
---|
This walkthrough is a continuation of Walkthrough: Creating a Cue Based on a FlowField. |
About This Walkthrough
This walkthrough illustrates the following tasks:
-
Creating a query object for calculating Cue data.
-
Adding a field for a new Cue in an existing table, and adding C/AL code to the field to get the data from the query object.
-
Adding a new Cue to an existing page for displaying the Cue in the Microsoft Dynamics NAV client.
-
Formatting the data in the Cue.
Roles
This walkthrough demonstrates tasks that are performed by the following user roles:
-
Microsoft .NET developer
-
Microsoft Dynamics NAV developer and IT professional
Prerequisites
To complete this walkthrough, you need:
-
Cue table 50001 Sales Invoice Cue and page 50001 Sales Invoice Cue page from Walkthrough: Creating a Cue Based on a FlowField.
This walkthrough uses these objects which you can create by using the instructions in the Walkthrough: Creating a Cue on a Role Center topic. The actual IDs and names of these objects might be different. -
Microsoft Dynamics NAV 2015 with a developer license.
-
The CRONUS International Ltd. demonstration database. This walkthrough uses the following objects:
-
Table 21, Cust. Ledger Entry
-
Page 25, Customer Ledger Entries
-
Table 21, Cust. Ledger Entry
Story
Viktor is a software developer who is working for CRONUS International Ltd. He has been asked to add a Cue to the Role Centers of sales order processors that shows the total sales for the month. To accomplish this, Viktor will create a Cue that is based on a query object that extracts the total sales for the month from table 21 Cust. Ledger Entry. The company already has a table (50001 Sales Invoice Cue) and page (50001 Sales Invoice Cue) that are used to display open sales invoices on the Order Processor Role Center. Viktor will add the new Cue to these objects.
Creating a Query for Calculating the Cue Data
First, Viktor creates a query object to calculate the number of open sales invoices from table 21 Cust. Ledger Entry.
To create a query for calculating the Cue data
In the Microsoft Dynamics NAV 2015 Development Environment, on the Tools menu, choose Object Designer, choose Query, and then choose New.
In Query Designer, on the first line, set Type column to DataItem, and then set the Data Source column to Cust. Ledger Entry (table ID 21).
Under the DataItem, add a Filter control for the Document Type field and a Filter control for Posting Date field of the Cust. Ledger Entry table. Then, add a Column control for Sales (LYC) field that uses a Totals method type to return a sum from the table. The Query Designer will look similar to the following table.
Type Data Source Name Method Type Method DataItem
Cust. Ledger Entry
<Cust. Ledger Entry>
Filter
Document Type
<Document Type>
Filter
Posting Date
<Posting Date >
Column
Sales (LYC)
<Sum_Sales_LCY>
Totals
Sum
Save the query as follows:
-
On the File menu, choose Save.
-
In the Save As window, in the ID field, enter an ID for the query object, such as 50001. The ID must be in a valid range for your solution.
-
In the Name field, enter Cust. Ledg. Entry Sales Query.
Select the Compiled check box, and then choose the OK button.
-
On the File menu, choose Save.
Adding the Table Field for the Cue Data
Viktor will add a normal field to the table 50001 Sales Invoice Cue for holding the Cue data. He will add a global function that returns the total amount of sales invoices for the current month from the query object that he created in the previous procedure.
To add a field for the Cue data
In the Microsoft Dynamics NAV 2015 Development Environment, open table 50001 Sales Invoice Cue from Object Designer.
Add a new field for the Cue. In the Field Name, enter Sales This Month and set the Data type to Decimal.
This defines the Cue data field.
Note By default, fields are normal fields as defined by the field's FieldClass Property.
To add C/AL code to the table calculate the Cue data
On the View menu, choose C/AL code to open the C/AL code for the table.
Add a global function that is called CalcSalesThisMonthAmount as follows:
On the View menu, choose C/AL Globals.
On the Functions tab, in the Name column, enter CalcSalesThisMonthAmount.
By default, all functions are set to local functions as specified by the Local Property, so you must change the function to be global as described in the following steps.
Select the new function, and then in the Tools menu, select Properties.
Set the Local property to No.
In the C/AL Globals window, select the new function, and then choose Locals.
The C/AL Locals window appears. From her you will add a return value and variables.
On the Return Value tab, set Name field to Amount and the Return Type field to Decimal.
On the Variables tab, add two variables as shown in the following table:
Name DataType Subtype CustLedgerEntry
Record
Cust. Ledger Entry
CustLedgEntrySales
Query
Cust. Ledg. Entry Sales
In C/AL code, add the following code on the CalcSalesThisMonthAmount function:
Copy Code CustLedgEntrySales.SETRANGE(Document_Type,CustLedgerEntry."Document Type"::Invoice); CustLedgEntrySales.SETRANGE(Posting_Date,CALCDATE('<-CM>',WORKDATE),WORKDATE); CustLedgEntrySales.OPEN; IF CustLedgEntrySales.READ THEN Amount := CustLedgEntrySales.Sum_Sales_LCY;
To save the table
On the File menu, choose Save.
Select the Compiled check box.
Choose the OK button.
Adding the Cue to the Role Center Page
To display the Sales This Month Cue on the Role Center, Viktor adds a new field for the Cue to the existing page 50001 Sales Invoice Cue.
To add the Sales This Month Cue to a page
In Object Designer, open the page 50001 Sales Invoice Cue.
To add a Cue, you add Field control under a CueGroup control. For this walkthrough, you will add the new Cue under the existing CueGroup control for Sales Invoices, after the Sales Invoices - Open field.
In a blank row under the existing CueGroup control, set the Type to Field, and then set the SourceExpr column to the "Sales This Month" field as follows.
Select the row, and then on the View menu, choose Field Menu.
The Field Menu window opens and displays the list of available fields from the Sales Invoice Cue table.
Select the Sales This Month field, and then choose the OK button.
In the Caption field, enter Sales This Month. The Caption value defines the text that appears below the Cue.
Page Designer should look similar to the following illustration.
Open the C/AL code for the page, and then add the following code to the OnAfterGetRecord Trigger to assign the Sales This month field to the CalcSalesThisMonthAmount function of table 50001 Sales Invoice Cue:
Copy Code "Sales This Month" := CalcSalesThisMonthAmount;
To set up a link (drill down) from the Cue to page 25 Customer Ledger Entries, do the following:
Select the Sales This Month field row, and then on the View menu, choose Properties.
In the Properties window, set the DrillDownPageID property to Customer Ledger Entries (ID 25) and choose the OK button.
Close the Properties window.
Save and compile the page.
The Cue is now available on the page. To view the page, in Object Designer, select the page 50001 Sales Invoice Cue, and the choose Run.
Formatting the Cue Data
Viktor wants to display the amount in the Cue so that it is preceded with "kr", which indicates Danish Krone is the currency. Additionally, he does not want to display any decimal places. To achieve this, he sets the AutoFormatType Property and AutoFormatExpr Property of the Cue field on the page.
To change the data format
In Page Designer, to open the properties for the Cue field, select the field, and then on the View menu, choose Properties.
In the Properties window, set the AutoFormatType property to 10.
This enables you to create a custom data format.
Set the AutoFormatExpr property to the following text.
Copy Code 'kr <precision,0:0><standard format,0>'
<precision,0:0>
specifies not to display any decimals places.<standard format,0>
specifies to format the data according to standard format 0.For more information about the precision and standard formats, see Formatting the Data in a Field
Close the Properties windows, and then save and compile the page.