Search Suggest

2023
Hotel Customer Feedback Power BI Dashbaord
D365FO
  • D365FO
  • X++
  • Company
  • Microsoft

A "legal entity" is an organization that has registered with a legal authority, legal entity can enter legal contracts and are required to prepare statements that report on their performance.

Microsoft Dynamics 365 supports of the concept of "multiple legal entity" or multiple company, which means one organization which have a production unit in UAE and another production unit in Qatar and their headquarters are in Saudi Arabia. In dynamics 365 finance and operations , we can create separate legal entities for eah of these organizations.

Each legal entity has its own customers. Products might be released per company, whereas prices might be defined per legal entity. While integrating data, the appropriate products and prices need to be sent to Common Data Service, but visibility to the right users also needs to be ensured. Similarly, opportunities in Common Data Service need to be created in the appropriate legal entity. Although workarounds exist, there is a need to provide out-of-box support for multiple legal entities. This new feature enables you to use the same project across multiple legal entities.

In Dynamics 365 finance and operation, it is possible to define all these legal entities as a company in the system. Depending upon the country where the legal entity is located, in dynamics 365 we can set up legal entity with country wise localization or region-specific features. country wise localization means, some parameters like currency, time zone etc… which will be different for different countries, in dynamics 365 we can set of all these parameters depending upon the country where company located.

In this article we will show you, how to create a legal entity with necessary steps, in dynamics 365 while creating a legal entity, there are a lot of details need to be filled. But here we will show you the necessary details which should be filled as mandatory.

In dynamics 365 we can see, some pre-defined legal entities, like USMF, DAT etc. with demo data. 

Lest start of creating new legal entity,

Once you login to the dynamics 365,

  • In the navigation pane, Under Modules > Organization Administration > Organization > Click on Legal Entities as shown below.

What is Legal Entity in Dynamics 365 F&O ? How to create a Legal Entity in Dynamics 365 F&O

  • On the action pane, Click +New Button. A dialogue will be appeared on the right side of the screen.
What is Legal Entity in Dynamics 365 F&O ? How to create a Legal Entity in Dynamics 365 F&O

In the dialogue box, 

  • In the Name field, enter the legal name of the company, 
  • In the Company field enter a value, which will the short name of the company like USMF is used for Contoso Entertainment System -USA
  • In the Country/ Region Field select the Country name where the company is located.

Once you have created a new legal entity, which will list in the list view along with the previously created legal entities located in the left side of the screen, then you can see around 16 fast tabs are available and need to be filled for various purposes as shown below.

What is Legal Entity in Dynamics 365 F&O ? How to create a Legal Entity in Dynamics 365 F&O

Here we only explain the 3 important tabs which need to be filled mandatory at initial time, all other details we can discuss through the future articles.

General Tab

In general tab,

  • In the Memo text area fill the general information / description about the legal entity.
  • In the search name field, you can fill the search name of the entity, you can use this search name for searching the legal entity in various forms. By default, legal entity name will be filled.
  • If the created legal entity is being used as a consolidation company, you can set the “Use for financial consolidation process slider” to “Yes” therwise select “No”. This means you cannot do any financial transaction under this company, this company is only used for reporting and consolidating the data.
  • If this legal entity is being used as an elimination company, set the “Use for financial elimination process” slider to “Yes” otherwise select “No”.
  • Next select the default language.
  • Select the time zone for the entity.

What is Legal Entity in Dynamics 365 F&O ? How to create a Legal Entity in Dynamics 365 F&O

Address Tab

In Address tab,

  • Click the +Add button. When you click the Add button, a table will be open, by default, in the “Name of description” column, legal entity name is displaying, In the "address" column Country/ Region is displaying. 
  • Click Edit button and fill the correct address of the legal entity.
  • You can add and edit more location addresses by clicking Add and edit button.

What is Legal Entity in Dynamics 365 F&O ? How to create a Legal Entity in Dynamics 365 F&O

Contact information

In the Contact information tab, 

  • Click +Add button for adding a new contact information record.
  • You can select Advanced button to modify an existing communication record. A pop-up dialogue will open, you can edit and update the contact information records.
  • You can select the methods of communication, such as email addresses, URLs, and telephone numbers etc from the drop-down list in the “Contact Number/ Address” column as shown below.

What is Legal Entity in Dynamics 365 F&O ? How to create a Legal Entity in Dynamics 365 F&O

Statutory reporting

In the Statutory reporting section, 

  • Enter the registration numbers that are used for statutory reporting the Statutory Reporting fast tab section, enter the registration numbers that are used for statutory reporting. 

Registration Numbers

In the Registration Numbers section,

  • Enter any information required by the legal entity. The fields are enabled as per the country of the legal entity. 

Bank Account Information

In the Bank Account Information section, 

  • Enter bank accounts and routing numbers for the legal entity. The bank details are recommended to be added in a separate module "Cash and bank management". 

Foreign Trade and Logistics

In the Foreign Trade and Logistics section, 

  • Enter shipping information for the legal entity. 

Number Sequences

In the Number Sequences section, 

  • Eiew the number sequences that are associated with the legal entity. We will discuss this in detail in later. 

Dashboard Image

In the Dashboard Image section, 

  • View or change the logo and/or dashboard image that is associated with the legal entity. 

Tax Registration

In the Tax Registration fast tab section, 

  • Enter the registration numbers that are used to report to tax authorities.

Tax 1099

In the Tax 1099 fast tab section, 

  • Enter 1099 information for the legal entity. (This is only necessary for a US-based company.) 
  • Finally Select Save.

Now you completed all the steps for creating a legal entity in dynamics 365 finance and operations. The legal entity is saved and is available among the list of legal entities. Also, the Legal Entity is available among the list of legal entities on Home Page as shown below.

What is Legal Entity in Dynamics 365 F&O ? How to create a Legal Entity in Dynamics 365 F&O

If you have any query about creating a legal entity in dynamics 365 finance and operations , please post a comment in the comment section.

Hotel Customer Feedback Power BI Dashbaord
D365FO
  • D365FO
  • X++
  • Currency
  • Dynamics

1. What is Dynamics 365 Finance & Operations?

Microsoft Dynamics 365 is a cloud-based business platform developed by Microsoft, which is designed as a cloud-based Enterprise Resource Planning (ERP) by Microsoft on the Azure Platform. The browser-based Microsoft Dynamics 365 Finance & Operations replaces the previous version on-premise version Dynamics AX. 

The responsibility of a Dynamics 365 Developer is to develop new modules or customize the existing modules. As Dynamics 365 is a high customization system, a developer with significant knowledge in D365 development can deliver high-quality solutions. 

The minimum Software requirements for Dynamics 365 Server is, It can be hosted locally or can use the Microsoft cloud platform, Microsoft Azure. A minimum of 16 GB of RAM and 2 CPU Cores are required, more RAM and CPU cores increase the speed of compilation. This is the basic requirement for running a Dynamics 365 application. 

The Three Tier Architectures of the Dynamics 365 process are, From the client environment (normally a Browser) request is sent to the AOS server. AOS server stands for Application Object Server will process this request. So all requests and responses are processed from the AOS environment. If required, this AOS is communicated with the Database server, and finally processed response is sent back to the client. This is the normal Three tier architecture followed by D365.

2. What is a form in D365 FO?

Forms in  d365 fo provide the user interface that people use to interact with the data they need to do their work. It is important that the forms people use are designed to allow them to find or enter the information they need quickly.

3. What is a Model in D365 FO?

As we know, the complete D365 Finance and Operation developments are based on these four terminologies Package, Model, Project, and Element. So as a developer you need to know processes how to create a model, how to update a model, and how to delete a model. 

Creating a model is a mandatory thing for any sort of customization in Dynamics 365. A model is a design-time concept. A particular model can contain multiple Visual Studio projects. Therefore you can say that a model is a collection of projects and a single project can have all or subset of elements from originating model. However, an association of a project is only with a single model. It is basically a unit of development/customization. Metadata for models is stored locally on an XML file called a descriptor XML.

4. What are the different types of Tables used in D365 FO?

1. Regular 

Regular tables are normal standard physical tables in the SQL server database. 

2. TempDB 

TempDB tables are the physical temporary tables held in the SQL server database. 

3. InMemory 

InMemory tables are temporary tables that are held in the memory and written to a local disc after reaching a certain limit of the system, especially in the Application Object Server (AOS).

5. What is the concept of extension in D365?

An extension is a way to add functionality to an object in D365FO without modifying the base code of that object. Your extensions are compiled into their own DLLs, which are separate from the D365 base system libraries. It also makes it easier for Microsoft to patch its SYS layer code. Microsoft has added to allow customization without allowing the base code to be changed because they plan to not allow any overlaying of SYS layer code.

6. What are OOPS concepts?

The main concepts of OOPS used in D365 FO are:

  • Class and Objects 
  • Data Abstraction: Showing only the essential information and hiding background details.
  •  Encapsulation: Wrapping of data member and method to a single unit. 
  • Inheritance:-The Flowing of property of the parent class to the child class. 
  • Polymorphism:-The property of using the same method again to perform different things.

7. What is AOT in D365FO? 

The Application Object Tree (AOT) is a tree view of all the application objects in Microsoft Dynamics D365FO. The AOT contains every object you need to customize the look and functionality of a Dynamics D365FO application.

8. Difference Between TempDB and InMemory Tables?

TempDB: 

  • TempDB temporary tables are faster than InMemory Temporary Tables.
  • TempDB temporary tables are maintained in the SQL Server database.
  • TempDB temporary tables support more features than standard physical tables.
  • TempDB temporary tables support More powerful joins with physical tables are possible.

InMemory:

  • InMemory temporary tables are instantiated in the active memory of the tier the process is running on. 
  • The process can run on the client tier or the server tier. 
  • The objects are held InMemory until the size reaches 128 KB. 
  • The dataset is then written to a disk file on the server tier. 
  • You can use InMemory temporary tables when the amount of data is small and Microsoft SQL Server round trips should be avoided.
  •  Both InMemory and TempDb tables can be used as data sources on forms.

9. What is the Chain Of Command (CoC) in D365

Chain of Command (CoC) is the term that describes how we customize or extend, the base Microsoft code in Microsoft Dynamics 365. Microsoft’s base objects and code cannot be changed directly in D365. However, we are able to make changes to separate objects and classes that are then combined with the existing base object to form the final version.

Basic Syntax : 

[ExtensionOf(classStr(CustTable))] public final class CustTable_Extension { public display str doSomething(int arg) { // Part 1 var s = next doSomething(arg + 4); // Part 2 return s; } }

10. Why Microsoft implemented CoC?

In the previous versions 2012 and before a programmer can change the Base Microsoft's source code directly from the developing environment. Microsoft identified the problem and from the next version, Microsoft re-architected the code and made it that Base Microsoft's source code and Objects cannot changed directly in D365. 

Microsoft releases new features and hot fixes as a part of product improvement. In this cases the new code should be merged with customized code, depending on the depth of the customization the complexity of the merging process will increase. So Microsoft found this difficulty and removed the feature. This benefits the users to update the hot fixes and feature updated of the product from Microsoft very fast, secure and safer than ever could before.

11. What are Delete Actions in D365?

Normally a delete action comes in to picture when a user is trying to delete a database record. Delete actions are used to maintain the data integrity and consistency of the database. At the time of development, a developer has to take care of the delete actions to implement in the project. Actually, a delete action is performed when related tables are existing in the project, and deleting records from any table has to be restricted to keep the database consistent.

In Microsoft Dynamics 365 Finance & Operations, there are four types of Delete Actions. 

  • None. 
  • Cascade. 
  • Restricted. 
  • Cascade + Restricted

12. What are EDT and Base Enum?

EDT stands for Extended Data Type and Base Enumerations (Enums) are data types that are created and managed in the development environment. Extended data types can be primitive data types like integers, strings, real numbers, and so on. EDT extends the original properties of the data type from which they inherit in addition some extra properties are added. To reuse its properties. The properties of many fields can change at one time by changing the properties on the EDT. Relations that can be assigned to an EDT are known as Dynamic relations.EDT relations are Normal and the Related field is fixed. Why not field fixed – field fixed works on only between two tables 1- 1 relation. And Related field fixed works on 1- many tables. so EDT uses a related field fixed. 

Examples for EDT: EDT Real, EDT Date, EDT String, etc.

Base enums are a fixed set of values, and integers in the database, which have a name (as referenced from X++ code) and a label (visible to users and translatable into different languages).  They cannot be added to in real-time by the application, only by developers, and often with significant overhead, hence how they are fixed.  You can have up to 255 values for Base enums.  The integers in the database will take on the values 0 through 254. 

The Application Object Tree (AOT) in Finance and Operations apps contains many existing EDTs and base enums that can be extended for use in your project, or you can create new data types. This module will focus on creating new data types. 

Example for Base Enum: You can add one Base Enum for holding the gender of the employee, you can create a Base Enum and rename it to BEGender and add new elements with names "Male" & "Female"  with integer values "0" & "1".

13. What is SSRS Report in D365?

Microsoft Dynamics 365FO users use the SSRS report for business reporting purposes. In Microsoft Dynamics 365 SSRS reporting feature is one of the significant features provided by Microsoft for their users. This SSRS report will help the users to get the right information about the business processes and transactions.

Based on the complexity of the SSRS reports, the development will be divided into two methods,

  • Query-Based Approach. 
  • Data Provider Approach.

14. What are the different types of classes used in the SSRS Report?

A DP (Data Provider) class will provide three data sets for the SSRS report. The same class will also provide information about report parameters to the report’s RDL through an attribute that links a DP class with the corresponding report Data Contract. 

A Controller class that will handle the report dialog form, setting the SSRS report design and the value of the hidden parameter. 

A Data Contract class that will define and carry the values of the report parameters.

15. What are Table Relations in D365?

A table relation associates two tables that contain related information. Usually, the primary key field of one table appears as a foreign key field of the related table. The table with the primary key is called the parent table. The table with the foreign key is called the child table. 

In Microsoft Dynamics 365 there are four types of table relations,

  • Normal Relation 
  • Field Fixed Relation 
  • Related Field Fixed Relation 
  • Foreign Key Relation

16. What are the different types of Menu Items available in D365?

Mainly three types of Menu items available In dynamics 365 F&O. They are, 

Display Menu Item: Use this type when the menu item will open a form. 

Output Menu Item: Use this type when the menu item will opening an SSRS report. 

Action Menu Item: Use this type when the menu item will run a batch job. Or some other process, such as run by a class.

17. What is an index in D365 FO?

An index is a table-specific database structure that speeds the retrieval of rows from a table. Indexes are used to improve the performance of data retrieval and occasionally to ensure the existence of unique records. 

There are two types of indexes unique and non-unique. Whether an index is unique is defined by the index’s AllowDuplicates property. When this property is set to No, a unique index is created. The database uses the unique index to ensure that no duplicate key values occur. The database prevents you from inserting records with duplicate key values by rejecting the insert.

18. What are display methods?

The display method modifier indicates that the method has a return value that can appear on a form or a report. A display method is any method that includes the display keyword as a method modifier. ... Form methods. Form data source methods. 

Display methods will help you to show the data from some other table or hardcoded strings. These are not bound controls and we cannot use a filter or sorting options.

19. What is Surrogate Key in D365?

A surrogate key is a system-generated value that acts as the primary key of a table. This value is typically used instead of a set of fields called the natural key which would typically act as the primary key of a table. Microsoft Dynamics AX 2012 or D365 uses RecId as the surrogate key. 

A surrogate key value has no meaning to people. A large number generated by the system, such as RecId, could be a surrogate key.

20. What is Microsoft LCS?

Lifecycle Services (LCS) for Microsoft Dynamics is a collaboration portal that provides an environment and a set of regularly updated services that can help you manage the application lifecycle of your implementations of the Dynamics 365 Finance and Operations apps.

21. What are the new features of D365?

Here the answers are based on the comparison with the Microsoft Dynamics AX version.

  • Coding & development is done by using Visual Studio IDE. In Microsoft Dynamics AX it was MorphX.

  • Visual Studio Team Services (VSTS) is used for version control.
  • D365 is now hosted in Internet Information Service (IIS).
  • Life Cycle Services (LCS) is the main tool used to deploy or move projects from one environment to another.
  • Power BI can be easily integrated with D365 with simple steps and configuration.
  • A Model made mandatory for customization and development. 
  • Data Entities are used for importing and exporting data, which can be easily created by users.
  • The override has been stopped, for any changes you can use extensions.
  • A chain of command (CoC) is used for making changes in Microsoft's base code to make a final version.
  • Form pattern made mandatory for UI development. You can only choose existing form patterns for UI development. 
  • You can access D365 only through the browser and there is no need to install the D365 client separately.
  • Enhanced integration with Excell and Odata Technologies.
  • Hotfixes and updates will be applied.
  • New workspace added.
  • Good integration with Office 365 Software



Some Useful Tags : 

d365 interview questions 2024
d365 finance and operations interview questions 2024
d365fo interview questions 2024
d365 interview questions and answers 2024
d365 technical interview questions 2024
d365 f&o interview questions 2024
dynamics 365 finance and operations interview questions 2024
d365 finance and operations functional interview questions 2024
d365 f&o functional interview questions 2024
Microsoft dynamics 365 for finance and operations interview questions 2024
d365 finance and operations functional interview questions and answers 2024
d365fo technical interview questions 2024
Microsoft Dynamics 365 business central interview questions 2024
d365 finance and operations technical interview questions 2024
d365 finance and operations interview questions and answers 2024
d365 f&o technical interview questions 2024
d365 functional consultant interview questions 2024
d365 SCM interview questions 2024
d365 ax technical interview questions 2024
interview questions on d365 finance and operations 2024
dynamics 365 for finance and operations technical interview questions 2024
d365 interview questions and answers 2024
d365 finance and operations functional interview questions 2024
d365 f&o functional interview questions 2024
Microsoft Dynamics 365 business central interview questions 2024
d365 functional consultant interview questions 2024
d365 interview questions and answers 2024
latest dynamics 365 interview questions 2024
dynamics 365 scenario-based interview questions 2024
d365 finance and operations functional interview questions and answers 2024
dynamics 365 functional consultant interview questions 2024

dynamics ax functional interview questions and answers 2024

SSRS reports in d365 finance and operations interview questions 2024

dynamics 365 scenario-based interview questions 2024

d365 interview questions 2024

dynamics CRM interview questions 2024

dynamics 365 interview questions 2024

Microsoft Dynamics 365 interview questions and answers 2024

latest dynamics 365 interview questions 2024

Dynamics ax functional interview questions and answers 2024

Microsoft Dynamics 365 interview questions and answers 2024

D365 finance and operations functional interview questions and answers 2024

Dynamics 365 functional consultant interview questions 2024

Dynamics 365 scenario-based interview questions 2024

Dynamics 365 interview questions 2024

Microsoft Dynamics 365 interview questions 2024

Microsoft Dynamics 365 interview questions answer 2024.

Latest dynamics 365 interview questions 2024

Microsoft Dynamics 365 interview questions and answers 2024

Dynamics 365 interview questions and answers 2024

CRM Dynamics 365 interview questions 2024

Dynamics 365 interview questions for experienced 2024

MS dynamics 365 interview questions 2024

Microsoft Dynamics AX Interview Questions 2024

Microsoft Dynamics 365 Interview Questions 2024

Microsoft dynamics CRM interview questions 2024 Updated.


Hotel Customer Feedback Power BI Dashbaord
D365FO
  • D365FO
  • X++
  • Currency
  • Dynamics

In Dynamics 365 Finance and Operations, the ‘select’ statement is commonly used to retrieve data from tables in the application's database. A select statement allows developers to fetch and manipulate data from a database. The data is loaded into table variables. Finally, these table variables can have methods where code be added to work with the data. Unlike other programming languages, writing select statements using x++ select statement is a very fast and easy.

Read More : X++ Select Statements

Read More  : X++ Select Statement with Where Clause

In Microsoft dynamics 365 finance and operations, while creating a table, system automatically allows the user to use the table variables or table buffers with a set of table properties including field names. Therefore, there is no need for a developer to manually create a class to work with the data in this table. The system essentially has created one for your use already.

Difference between While select and Select Statement

In the previous article we already read that a select statement can be used or only can return one record and store the results in the table buffer. But in many situations, we need to retrieve many records on a single select statement, in these cases we need to use a while statement, a ‘while select’ statements are used to find one or more records.

Here you can see one simple select query example which select the first record of VendTable and store into the table buffer vendTable.

internal final class SelectQueryExample

{ 

   public static void main(Args _args)

   {

       VendTable vendTable;

       select * from vendTable;

       info(strFmt("Vendor Account Num = %1", vendTable.AccountNum));

       select vendTable;

       info(strFmt("Vendor Account Num = %1", vendTable.AccountNum));

}

}

Above both select queries retrieve one record as shown in the below screenshot.

X++ While Select Statement in Dynamics 365 Finance and Operations

X++ Next Keyword

We have a requirement to retrieve more than one vendor account number, Microsoft introduced a new keyword called ‘Next ‘Keyword. Which we can use multiple records to retrieve from a table buffer,

Syntax of Next keyword,

You can see the below snippet example to understand the use of the Next keyword, 

internal final class SelectQueryExample

{ 

   public static void main(Args _args)

   {

       VendTable vendTable;

       select * from vendTable;

       info(strFmt("Vendor Account Num = %1", vendTable.AccountNum));

       select vendTable;

       info(strFmt("Vendor Account Num = %1", vendTable.AccountNum));

       next vendTable;

       info(strFmt("Vendor Account Num = %1", vendTable.AccountNum));

       next vendTable;

       info(strFmt("Vendor Account Num = %1", vendTable.AccountNum));

       next vendTable;

       info(strFmt("Vendor Account Num = %1", vendTable.AccountNum));

}

}

Here we need to write the separate lines of codes to retrieve the multiple number of vendor Account Number from a single table buffer. So, if we need to retrieve ‘n’ number of Vendor Account Number, we need to write ‘n’ number of lines by using next keyword.

But this is not practical, if we have thousands of records, we are not able to write thousands of lines of codes with next keyword. 

In these cases, we are using while statement.

While Select Statement

In Dynamics 365 Finance and Operations, the "while select" statement is commonly used in X++ programming language to iterate through records in a table or a view and execute a block of code if a specified condition is true. This statement is often used for data manipulation and processing.
Like a select statement, x++ code is written to specify what records should be retrieved from the database. However, a while select statement should be used when the number of records being retrieved.

So, you can rewrite the code like this,

internal final class SelectQueryExample

{ 

   public static void main(Args _args)

   {

       VendTable vendTable;

       while select vendTable;

{

        info(strFmt("Vendor Account Num = %1", vendTable.AccountNum));

        }

}

}

In this example you can see, we have declared one table buffer vendTable, In the next line, the system starts by looking at the query part of the select statement. Here before the select statement we have written the keyword ‘while’.

In this case: ‘while select vendTable. This tells the system to retrieve every record in the table named VendTable. Next, at the start of the curly brace, the system will take all the values in the first record retrieved and load them into the vendTable table buffer variable. After that, the ‘info(strFmt("Vendor Account Number = %1", vendTable.AccountNum));’ line of code will print out the sales order number to the screen. Finally, the system will see the ending curly brace, and jump back to the starting curly brace.

While select statement with where clause

In Dynamics 365 Finance and Operations, the "while select" statement is commonly used in X++ programming language to iterate through records in a table or a view and execute a block of code if a specified condition is true. This statement is often used for data manipulation and processing.

You can use a where clause with while statement , which will retrieve the records only if a specified condition is true. If the specific condition is false, system will not retrieve any records. While select statement with where clause is generally used to retrieve multiple records which are satisfying a specific condition.

internal final class SelectQueryExample

{ 

   public static void main(Args _args)

   {    

while select AccountNum, Name, Balance from CustTable

    where CustTable.Balance > 1000

{

    info("Account Number: " + CustTable.AccountNum);   

info("Customer Name: " + CustTable.Name);   

info("Balance: " + CustTable.Balance);

}

}

}

In this example:

  • while select: Initiates the loop.
  • AccountNum, Name, Balance: Specifies the fields to be selected from the "CustTable."
  • from CustTable: Specifies the table from which records are selected.
  • where CustTable.Balance > 1000: Sets the condition that only records with a balance greater than 1000 will be selected.
  • { //code to be executed for each selected record }: The block of code inside the curly braces will be executed for each record that meets the specified condition.This example selects records from the "CustTable" where the balance is greater than 1000 and displays the account number, customer name, and balance for each selected record.Using the "while select" statement with a "where" clause allows you to process a subset of records based on specific conditions, providing flexibility in handling data in Dynamics 365 Finance and Operations.

Conclusion

After reading this article, i expect you can get the basic idea about 'x++ select statement' and 'x++ while select statement', for writng efficient codes to retrive many records in a single statement with a condition or without a condition , you can use while select statement. if this article is useful, try to share your friends and social media platform. Happy coding with d365snippets.

Hotel Customer Feedback Power BI Dashbaord
D365FO
  • D365FO
  • X++
  • Dynamics
  • Microsoft

In the previous article, I explained what is x++ select statements and steps for writing An X++ Select Statement in Dynamics 365 finance and operations. In this article, i am writing the continuation of the x++ select statement with a where clause is used with select statement.

A select statement allows developers to fetch and manipulate data from a database. The data is loaded into table variables or table buffers. Finally, these table buffers can have methods where code be added to work with the data. Unlike other programming languages , writing select statements using x++ select statement is a very fast and easy. 

In Microsoft dynamics 365 finance and operations , while creating a table, system automatically allows the user to use the table variables or table buffers with a set of table properties including field names. Therefore, there is no need for a developer to manually create a class to work with the data in this table. The system essentially has created one for your use already.

Select Statement Where Clause

A select statement without where clause only return one record and store the results in the table buffer, The 'where' clause in the select statement is used to filter the records returned by the query based on specified conditions. To do that, we will add a ‘where’ clause to our select statement. Change the code to look like this:

internal final class SelectQueryExample
{

   public static void main(Args _args)
   {
      CustTable custTable;
      select * from custTable where custTable.AccountNum == “CUS10001”;
      info("AccountNum: " + custTable.AccountNum);
   }
 
}

In this example: 

  • select * from custTable: This part of the statement selects all fields from the CustTable table. 

  • where custTable.AccountNum == 'CUS10001': This part filters the records to only include those where the AccountNum field is equal to 'CUS10001'.

You can use various comparison operators in the 'where' clause, such as == (equal), != (not equal), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to). 

Additionally, you can use logical operators (&& for AND, || for OR) to combine multiple conditions in the 'where' clause.

In our example a 'where' clause essentially used to return the record we want, the AccountNum field is the primary field of the unique index on this table. which means AccountNum field should not be duplicated and should be unique. So when we filter the account number with the required value which will return only one record that we need actually.

But if we are not using the 'where' clause the system will store the table buffer with the first record which find.

The major difference of x++ select query with where clause to the normal sql query is ,first difference is, in normal sql queries we use '=' one equal to sign, but with x++ we use two equal to signs '==', Second difference is a table buffer variable must be used with x++ select queries.

In conclusion, without the ‘where’ cause the system would just be picking the first record it finds. which is not very helpful. Now, when werun the above code, the system will select the record where the AccountNum equal to the account number we pass, which acts as a filter and returns the value what we exactly want. As a beginner this topic will help you to learn more about x++ select statements , in the next article we will learn 'what is a field list and what is the use of field list and how to write a x++ statement with field list'.

Hotel Customer Feedback Power BI Dashbaord
D365FO
  • D365FO
  • X++
  • Currency
  • Dynamics

In Dynamics 365 Finance and Operations (previously known as Dynamics AX), you can use the X++ programming language to write custom logic and queries. The SELECT statement is commonly used to retrieve data from tables in the application's database. Here's the basic syntax for a SELECT statement in Dynamics 365 Finance and Operations:

A select statement allows developers to fetch and manipulate data from a database. The data is loaded into table variables. Finally, these table variables can have methods where code be added to work with the data. Unlike other programming languages , writing select statements using x++ select statement is a very fast and easy.

In Microsoft dynamics 365 finance and operations , while creating a table, system automatically allows the user to use the table variables or table buffers with a set of table properties including field names. Therefore, there is no need for a developer to manually create a class to work with the data in this table. The system essentially has created one for your use already.

Example :

Here is one simple example which helps you to learn concept more easily. 
internal final class SelectQueryExample
{

   public static void main(Args _args)
   {
      CustTable custTable;
      select * from custTable;
      info("AccountNum: " + custTable.AccountNum);
   }
 
}

Steps for writing An X++ Select Statement


1. Define a Table Buffer

Here in the first line, a table buffer of type ‘CustTable’ is defined, with the name ‘custTable’. Where CustTable is the type of Table and custTable is the name of the table variable. 

2. Basic Select Statement

Once you created a table variable or table buffer, you can easily acces the data from the table by using the select  keyword, this is similier to SQL select query statement. Initially the table buffer will be empty, but after writing the select * from custTable statement, table buffer that should be populated with the data from CustTable.

3. Retrieve required table field

Once table buffer is popualted with the table data, you can fetch required field values by using field names. 

In our example while using the x++ code custTable.AccountNum;, system retrieve the account numbers from the table buffer custTable which was already popluated.

To follow along yourself, create a new D365 project and solution in Visual Studio.

Next, add a ‘Runnable class (Job)’ to the solution. Specifically, right click on the project, and select Add>New Item. Then, select the ‘Runnable Class (Job)’ item. Enter a name, such as ‘SelectStatement’. Finally, click the ‘Add’ button.

X++ Select Statements Dynamics 365 Finance and Operations

Once you created a Runnable Class (Job), copy and paste the above code in between the curl brackets of main method as shown below image.

X++ Select Statements Dynamics 365 Finance and Operations

Similier way , you can access other CustTable fields by usng the filed names.

Conclusion

In Microsoft dynamics 365 using x++ query statements , it is easy to manipulate data of a table, in other programming languages we need more lines of codes to manipulate the table data. This article will be helpful for beginners to understand the concepts of table buffer and x++ query statements especiall select query statements. In the next articles we will read more about select queries by using where clause, Field List, Firstonly etc. Hope this article is helpful. Happy cosing with d365snippets.

Some useful queries

What is the select statement in x++?

What is the difference between select and while select?

How do you write an X++ select statement?

What is the purpose of the select statement in access?


Hotel Customer Feedback Power BI Dashbaord
D365FO
  • D365FO
  • X++
  • Currency
  • Dynamics
In Dynamics 365 Finance and Operations, date functions play a crucial role in performing various operations related to date and time manipulation within the application. These functions are used to handle and process date-related data efficiently.

These date functions are particularly useful when creating custom business logic, workflows, or reports that involve date calculations or validations. They can be used in various areas of the application, such as in X++ code, formulas, workflows, and SSRS reports.

For example, if you need to calculate the due date for an invoice by adding a specific number of days to the invoice date, you can use the dateAdd() function to achieve this efficiently.

Keep in mind that Dynamics 365 Finance and Operations may have updates and enhancements over time, so it's always a good practice to refer to the official documentation for the most up-to-date information on available date functions and their usage within the platform.

There are a lot of functions in dynamics Ax for dates. Followings are some date time functions I used extensively. Some commonly used date functions in Dynamics 365 Finance and Operations include:

1. How to get Start Date and End Date of a Month in dynamics 365 Finance and Operations

In Dynamics 365 Finance and Operations a date function DateStartMth(myDate) and endmth(myDate)  functions are used to to get Start Date and End Date of a Month from the given date in dynamics 365 finance and operations,This function returns Start Date and End Date of a Month that is used by the client.

Here i have created one runnable class DateFunctionsJob. Once you created the class , you can copy and paste the below codes as per your requirements.

Start Date of the Month

internal final class DateFunctionsJob

{
   public static void main(Args _args)
   {        Transdate dateToday;

       TransDate startDateOfMonth;

       dateToday =today();

       startDateOfMonth=DateStartMth(dateToday);

       info(strfmt("Start Date Of Month - %1",startDateOfMonth));

    }
}

Output :
Start Date Of Month - 7/1/2023

End Date of the Month

internal final class DateFunctionsJob

{    public static void main(Args _args)    {
     Transdate dateToday;

     TransDate endDateOfMonth;

      dateToday =today();

      endDateOfMonth=endmth(dateToday);

       info(strfmt("End Date Of Month - %1",endDateOfMonth));

    }

}

Output :
End Date Of Month - 7/31/2023

2. How to split datetime into hour minutes and seconds with different timezone in dynamics 365 Finance and Operations

In Dynamics 365 Finance and Operations a date functions DateTimeUtil::hour(myCurrentDateTime), DateTimeUtil::minute (myCurrentDateTime);and DateTimeUtil::second(myCurrentDateTime); are used to tto split datetime into hour minutes and seconds with different timezone from the given datetime in dynamics 365 finance and operations,This function returns to split datetime into hour minutes and seconds with different timezone that is used by the client.

internal final class DateFunctionsJob

{
   public static void main(Args _args)
   {
     TransDateTime myCurrentDateTime;

    int      hours;

    int      minutes;

    int      seconds;

myCurrentDateTime=DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(),Timezone::GMTPLUS0530CHENNAI_KOLKATA_MUMBAI);

hours=DateTimeUtil::hour(myCurrentDateTime);

minutes=DateTimeUtil::minute(myCurrentDateTime);

seconds=DateTimeUtil::second(myCurrentDateTime);

info(strfmt('Current Date Time - %1 ',datetime2str(myCurrentDateTime)));

 info(strfmt('Hours %1 - Minutes %2 - Seconds %3',int2str(hours),int2str(minutes),int2str(seconds)));

    }
}

Output:
Current Date Time - 7/23/2023 12:00:03 pm

Hours 12 - Minutes 0 - Seconds 3

Here you can change the time zone by selecting the timezone in the code myCurrentDateTime=DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(),Timezone::GMTPLUS0530CHENNAI_KOLKATA_MUMBAI);

3. How to get current system Time in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function timenow() is used to get the current system time in dynamics 365 finance and operations,This function returns the current time that is used by the client.

internal final class DateFunctionsJob

{
   public static void main(Args _args)
   {
     info(strfmt('Current System Time - %1',time2str(timenow(),1,1)));

    }
}

Output:
Current System Time - 07:01:29

4. How to get current system Date with timestamp in dynamics 365 Finance and Operations

In Dynamics 365 Finance and Operations a date function DateTimeUtil::getSystemDateTime(); is used to get current system DateTime (with hours, minutes, seconds) in dynamics 365 finance and operations,This function returns the current system DateTime (with hours, minutes, seconds) that is used by the client.

internal final class DateFunctionsJob

{
   public static void main(Args _args)
   {

       utcDateTime   mySystemDateTime = DateTimeUtil::getSystemDateTime();

       info(strfmt('Current System Date with Time Stamp - %1',mySystemDateTime));

    }
}

Output:
Current System Date with Time Stamp - 7/23/2023 09:46:55 am

5. Convert UtcDateTime to string in dynamics 365 Finance and Operations

In Dynamics 365 Finance and Operations a function DateTimeUtil::toStr(myDateTime) ; is used to Convert UtcDateTime to string in dynamics 365 finance and operations,This function returns the converted UtcDateTime to string that is used by the client.

internal final class DateFunctionsJob

{
   public static void main(Args _args)
   {

        utcDateTime   mySystemDateTime = DateTimeUtil::getSystemDateTime();       

str myStringSystemDateTime= DateTimeUtil::toStr(mySystemDateTime);   

        info(strfmt('String UtcDateTime is - %1 ',myStringSystemDateTime));

    }
}

Output:
String UtcDateTime is - 2023-07-23T09:56:33

6. Convert datatime to string into a specific format in dynamics 365 Finance and Operations

In Dynamics 365 Finance and Operations a function DateTimeUtil::toStr(myDateTime) ; is used to Convert datatime to string into a specific format in dynamics 365 finance and operations,This function returns the converted datatime to string into a specific format that is used by the client.

internal final class DateFunctionsJob

{
   public static void main(Args _args)
   {

       System.DateTime myDateTime = System.DateTime::get_UtcNow(); 

       str utcTimeAsStr =myDateTime.ToString('yyyy-M-dd_HH:mm:ss');   

       info(strFmt("String Datetime with New Format : %1 ",utcTimeAsStr));

    }
}

Output:
String Datetime with New Format: 2023-7-23_10:26:58

in the output result you can see the new date format , you can change the format as per the requirements.

7. How to check if a utcDateTime is Null in dynamics 365 Finance and Operations using X++

In Dynamics 365 Finance and Operations you can use the condition if(MyUtcDateTime== Global::utcDateTimeNull()) to check if a utcDateTime is Null in X++.

internal final class DateFunctionsJob

{
   public static void main(Args _args)
   {

       utcdatetime MyUtcDateTime;

       if(MyUtcDateTime== Global::utcDateTimeNull())

       {

           info(strFmt("MyUtcDateTime has Null value "));

       }

    }
}

Conclusion

First and foremost, Dynamics 365 date functions significantly enhance the efficiency and accuracy of date-related calculations. Tasks such as adding or subtracting days, months, or years, determining the difference between two dates, or extracting specific components (e.g., day, month, year) from a date become seamless and error-free with the help of these functions. By automating these processes, organizations can save valuable time and resources, allowing their teams to focus on more strategic and value-added activities.

Tags

X++ date runtime functions - Dynamics 365 Finance and Operations
Date and Time Functions in Dynamics 365 Finance and Operations
Using the Date Function in Microsoft Dynamics 365 Finance and Operations
Date functions in dynamics 365 Finance and Operations
Date functions in dynamics 365 FO