Unleashing Dynamics 365 Excellence: Your Source for Pro Tips and Snippets at D365Snippets.com

Our blog provides a curated collection of tips, tricks, and code snippets that streamline your workflow and enhance your proficiency.
Unleashing Dynamics 365 Excellence: Your Source for Pro Tips and Snippets at D365Snippets.com

Custom Table Methods Through Extension in D365 with Example

0

In the previous article we already discussed the topic Query Based SSRS Report creation in Microsoft Dynamics 365 Finance and Operations. There you can see all the necessary steps to configure and generate query based SSRS reports in Microsoft Dynamics 365 Finance and Operations. 

In this article i will show you How to create Custom Table Methods Through Extension in Microsoft Dynamics 365 Finance and Operations. If you are a beginner You can also access this free VM from Microsoft learning portal, read the article Microsoft provides a VM Mode for a free,web based virtual machine environment for D365 F&O Learners.

Imagine a requirement that you have add one more column to the all sales orders  grid view under the  Accounts Receivable menu.


Custom Table Methods Through Extension in D365 Finance and Operations D365 snippets

The All sales order  form showing the list of all sales order summaries with the columns Sales Order refer no, Customer Account, Customer Name , Order type , Invoice account etc...Here we need to display one more extra column TotalSales which gives the total sales value of each sales order.

Custom Table Methods Through Extension in D365 Finance and Operations D365 Snippets

For adding one extra column in All Sales order grid view, we have to create one custom table method by extending the SalesTable. This method is also know as Display Method.

Create a Model

Here i am creating one model with model name D365SnippetsModel  all our development steps are based on the model D365SnippetsModel.For creating a model, open visual studio and select Dynamics 365 menu. Under Model Management choose create model, fill the required values as shown below image.

Custom Table Methods Through Extension in D365 Finance and Operations D365 Snippets

Create a project

After creating model create a project with name CustomTableMethod.

Custom Table Methods Through Extension in D365 Finance and Operations D365 Snippets

Create a class

Here we are creating one class named SalesTable_Extension which extending the table SalesTable. In D365 sales header details are stored in SalesTable and associated sales transaction details stored in SalesLine Table. The reference key for the tables are SalesId .

For generating TotalSales value we have to write  X++ code for multiplying  the sum of line item quantity SalesQty with the sum of line item unit price SalesPrice  by extending the SalesLine table . One display method is created getTotalSalesOrderAmount(), all the x++ logic we are writing under this method.

Custom Table Methods Through Extension in D365 Finance and Operations D365 Snippets

Extend the form 

All the core steps are completed now. Method getTotalSalesOrderAmount() returns the TotalSales value of each Sales Orders. Next step we have to create one more column in the GridView of the form SalesTableListPage which lists all the sales orders summary.

For this create extension of the form SalesTableListPage, for this right click SalesTableListPage from AOT  and click on create extension. After few second the form is extend to the project. see the below image for more clarification.

Custom Table Methods Through Extension in D365 Finance and Operations D365 Snippets

Add TotalSales Column

For adding TotalSales  column in the form SalesTableListPage we have to add one more FormControl field with Real Type, which holds the TotalSales  value in the form SalesTableListPage. For adding one Real Type FormControl  field double click on the form extension, visual studio opens one design window. 
Right click on the Grid --> New  -- > Real.

Custom Table Methods Through Extension in D365 Finance and Operations D365 Snippets

Custom Table Methods Through Extension in D365 Finance and Operations D365 Snippets

Custom Table Methods Through Extension in D365 Finance and Operations D365 Snippets

Custom Table Methods Through Extension in D365 Finance and Operations D365 Snippets

After creating FormControl field with Real Data Type go to the property window, change the Name property of FormControl  to SalesTotal. Also change the  DataSource, here SalesTable is the data source and put the display method getTotalSalesOrderAmount() as the  Data Method.In X++ for calling a static Data Method is by using the syntax,

ClassName :: MethodName();

Custom Table Methods Through Extension in D365 Finance and Operations D365 Snippets

So here we put SalesTable_Extension::getTotalSalesOrderAmount();  in the Data Method property of the FormControl  TotalSales. Now all the steps are over. finally deploy the project.

Custom Table Methods Through Extension in D365 Finance and Operations D365 Snippets

Go to the functional environment and go to Accounts Receivable then select All Sales Order menu, You can see the TotalSales column in the Grid view, which shows the total sales amount of each sales order. Customization is over.


Custom Table Methods Through Extension in D365 Finance and Operations


Post a Comment

0Comments
Post a Comment (0)