Search Suggest

February 2022

As we already discussed the topic in the previous post How to Import Records from Excel Using X++ Code in D365FOIn this article, I would like to show  "How to import data from an XML file or Read data from an XML file using x++ code in Microsoft Dynamics 365".

If you are a beginner or learner, you don’t have a dynamic 365 developing or functional environment, you can use Microsoft free Virtual Machine. Learn How to Set Up a Free Virtual Machine for Dynamics 365 Development

What is XML File?

An XML file is an extensible markup language file, and it is used to structure data for storage and transport. In an XML file, there are both tags and text. The tags provide the structure to the data. The text in the file that you wish to store is surrounded by these tags, which adhere to specific syntax guidelines. 

At its core, an XML file is a standard text file that utilizes customized tags, to describe the structure of the document and how it should be stored and transported.

Here I am giving one simple example to make you understand how can we read an XML file which is stored in the local directory. This post will help you to read an XML file that is in a simple format as shown below. You can create a Job that reads an XML file.

<?xml version="1.0" encoding="UTF-8"?>
<xml>
  <SalesTable RecId="525693083">
      <SalesId>SID0001</SalesId>
      <SalesName>ABC Trading</SalesName>
      <CustAccount>1234567890</CustAccount>
  </SalesTable>
  <SalesTable RecId="5637163083">
      <SalesId>SID0002</SalesId>
      <SalesName>XYZ Exporting</SalesName>
      <CustAccount>1234567890</CustAccount>
  </SalesTable>
</xml> 

Here we are using the above simple XML format for reading the XML data. In this example, I hard-coded the path of the XML file which is stored in the local machine by using the x++ code  #define.filename(@"D:\Customer.xml") . you can also use file chooser dialogues by adding your own additional codes and choosing the XML file dynamically. The XML file Customer.xml stores the details of customers' using the tags SalesId, SalesName, and CustAccount.

Here I created one Runnable Job(Class),

class XMLReadOperation
{
   
   public static void main(Args _args)
   {
       XmlDocument doc;
       XmlNodeList data;
       XmlElement nodeTable;
       XmlElement nodeId;
       XmlElement nodeName;
       XmlElement nodeCustAccount;
       #define.filename(@"D:\Customer.xml")
       doc = XmlDocument::newFile(#filename);
       data = doc.selectNodes('//'+tableStr(SalesTable));
       nodeTable = data.nextNode();
       while (nodeTable)
       {
           nodeId = nodeTable.selectSingleNode(fieldStr(SalesTable, SalesId));
           nodeName = nodeTable.selectSingleNode(fieldStr(SalesTable, SalesName));
           nodeCustAccount = nodeTable.selectSingleNode(fieldStr(SalesTable, CustAccount));
           info(strFmt("%1 – %2 – %3",nodeId.text(),nodeName.text(),nodeCustAccount.text()));
           nodeTable = data.nextNode();
       }
   }
 
}

How it works…

Here we first create a new XmlDocument. We create it from the file and hence we have to use its newFile() method. Then we get all the document nodes of the table as XmlNodeList. We also get its first element by calling the nextNode() method.

Next, we loop through all the list elements and do the following:

 1.  Get the salesId node as an XmlElement.
 2. Get salesname node as an XmlElement.
 3. Get custaccount as an XmlElement.
 4. Display the text of nodes in the Info log.
 5. Get the next list element.


In this way, we retrieve the data from the XML file. A similar approach could be used to read any other XML file.

Importing Data from An XML File in Dynamics 365 with Example.


Set XMLReadOperation as Set as StartUp Object and run the project. Info method displays the data stored in the Csutomer.xml 


Importing Data from An XML File in Dynamics 365 with Example.


Hope this post will be very useful for beginners. Please comment and share. In the next posts, I will show how to read XML files from URL in dynamics 365.
Happy coding with D365 Snippets 🙂.


Tags

Importing data from an XML file
How to read data from xml file in dynamics 365
How to read data from xml file in dynamics AX
READ XML FILE FROM URL IN AX 2012
How to importing Data from An XML File in Dynamics 365
How do I import data into Dynamics 365 finance and operations?
How do I import data into Dynamics CRM 365?
How do I import an XML file into Excel 365?
How do I import into Microsoft Dynamics?
dynamics 365 import xml file
data migration d365 finance and operations
how to read xml file in ax 2012
business central xmlport import example
d365 data management auto default
d365fo master data
application platform flighting errors
entity data management

In this article we can discuss “How to Create Number Sequence in Microsoft Dynamics 365 for Finance and Operations by Number Sequence form.If you are a beginner or new to dynamics 365 Finance & Operations, you can use Microsoft'f Free Virtual Machine. Learn How to Set Up a Free Virtual Machine for Dynamics 365 Development

In Microsoft Dynamics 365 Number sequences are used generate readable, unique identifiers for master data records and transaction records for record identification. Generally, Number sequences are specially formatted numbers which used to refer a master record or transaction record in any ERP Systems. A master data (for example: Vendor Master, Customer Master, Products Master etc…) or transaction data (for example:  Supplier Order, Payment Voucher, Journal Entry etc…) requires an identifier or a reference number which are used for identifying the records in future. Before you are creating a new record for a reference, you must set up a number sequence and associate it with the reference.

Dynamics 365 includes company-specific number sequences and number sequences on the enterprise level. The scope parameters of a number sequence control, whether it is shared or specific to a company. Once you set up a number sequence for a particular table it will generate number sequences or reference number automatically.

So, when we are developing a custom functionality, often one of the tasks is to add a new number sequence to the system to support newly created tables.

We can add a number sequence to the system is a two-step process. First, we create the number sequence itself; second, we start using it in some form or from the code.

Use of Number Sequences

  • Number sequences in Dynamics 365 Finance and Operations (Dynamics 365) are used to generate and manage the unique identifiers for different types of records throughout the system systematically and automatically.
  • Number sequences can be utilized to help easily identify certain types of records throughout the system just by adding a certain prefix or numbering convention to the number sequence that clearly indicates the type of record.
  • Once you set up a number sequence for a particular table it will generate number sequences or reference number automatically. No worry about the next Sequence number.
  • By putting the prefixes in Number sequences, you can easily identify the transaction type, transaction year, transaction company details.
  • When you set up number sequences for document and transaction numbers, it is a good idea to avoid overlapping of number sequences for the different documents in order to facilitate tracking of transactions.

How to create a Number Sequence

For creating a number sequence list page navigate to Organization administration > Number sequences > Number sequences. Here First, we will look at the number sequence form, and I will explain what all the fields mean and what you need to know when setting up a number sequence.

How to Create Number Sequence in Microsoft Dynamics 365 for Finance and Operations

In the number sequences list page we are presented with all number sequences from all companies. We can start to filter this down by using the “Area” and “Reference” filters to find the number sequence we are looking for. In this case I’m going to filter on the “Accounts payable” area and “Vendor account” reference. This is going to show me all the number sequences with vendor account as a reference.

How to Create Number Sequence in Microsoft Dynamics 365 for Finance and Operations

  • Next click the hyperlink to open the number sequence form.
  • The “Number sequence code” is the unique identifier of the number sequence and is what you would select when you associate a number sequence to a record type (reference) in the system.
  • The “Name” field is just a description field.
  • The “Scope” field is a way you can define the scope of the number sequence. For example you may want a certain number sequence to be shared across companies and all others to be per legal entity or company.
  • The “Segments” section is where you can build the format for the number sequence. In the example below the number sequence starts with the legal entity identifier as a prefix followed by a dash “-“ as a constant value and then a sequential string of numbers length of which is six digits. You can also see that it shows you a preview of how the number sequence will look in the “Format” field.


How to Create Number Sequence in Microsoft Dynamics 365 for Finance and Operations

How Number Sequences Work

In this section I’m going to show you how number sequences work with real examples and explanations. We will continue with the vendor number sequence example. You have seen the number sequence form and what the fields do now let’s actually see where you put the number sequence to use.

How to Create Number Sequence in Microsoft Dynamics 365 for Finance and Operations

  • Since we are using a vendor account number sequence navigate to Accounts Payable > Setup > Accounts payable parameters.
  • Click the “Number sequences” tab.
  • Here you can see all of the “References” which really just means record types that you can assign number sequences to. I want to assign the number sequence we having looking at “Acco_1312” to the “Vendor account” reference.


How to Create Number Sequence in Microsoft Dynamics 365 for Finance and Operations

  • Now let’s navigate to Accounts payable > Vendors > All vendors.
  • Click the “New” button to create a new vendor. As you can see the vendor account number is “USPI-000002”. This is the format that was defined on the number sequence and it used the “Next” value which was “2”.


How to Create Number Sequence in Microsoft Dynamics 365 for Finance and Operations


You can see this created sequence number for the vendor account through status for number sequence form.

How to Create Number Sequence in Microsoft Dynamics 365 for Finance and Operations

Through this form you can manipualte the number sequesnce, As you can see if I create a new vendor record the sequence is “USPI-000003” which is the next number in the sequence.You can click the “History” button to see all of the history associated with the number sequence.

How to Create Number Sequence in Microsoft Dynamics 365 for Finance and Operations


General Settings in Number Sequences 

The numeric first (Smallest) and last (Largest) number of a number sequence are specified on the tab General of the number sequence detail form. The field Next shows the number, which the number sequence applies to the next number. You can change the next number, but you have to make sure to avoid duplicate keys and gaps in continuous numbers.

The slider Manual controls whether numbers have to be entered manually. If the slider To a lower number or To a higher number is set to “Yes”, you can change the numbers that are assigned from the number sequence. 

The slider Continuous prevents gaps in a number sequence. Set this slider only in number sequences to “Yes”, which actually require continuous numbers. Voucher numbers often require continuous numbering, since it is a statutory requirement in many countries.

Conclusion 

Through this article you can get the basic concept of generating number sequence in Microsoft Dynamics 365 finance & operations. We can utilized Number sequences to help easily identify certain types of records throughout the system just by adding a certain prefix or numbering convention to the number sequence that clearly indicates the type of record. Please share this article to Dynamics 365 enthusiasts. In next artice we will discuss how to create this number sequence through x++ coidng.

Happy coding with D365 Snippets 🙂.


Tags

Number sequences overview - Dynamics 365
Set up number sequences using a wizard
What is number sequence in d365?
How do I create a number sequence in d365?
How do you find the number sequence in d365?
What is numbering sequence?
How do you create a number sequence for existing module and also for new module?
How do you create a number sequence in AX 2012?
Number Sequences Explained: D365 Finance and Operations
How to Create a Dynamics 365 Number Sequence?
Steps to create number sequence in D365FO
number sequence in ax 2012 step by step
create number sequence in d365 x++
number sequence in ax 2012 step by step
create number sequence in d365 x++
number sequence method in d365
d365 number sequence cleanup
d365 number sequence status list
number sequence group in d365
number sequence cache candidates
the format cannot contain the specified interval. d365
create new number sequence d365
d365fo number sequence setup
creating number sequence in d365
setup number sequence d365
dynamics 365 number sequence
d365 f&o number sequence
d365 sales sequence
number sequence identifier
Set up number sequences
Number Sequences Explained: D365 Finance and Operations 
Generate new number sequence using OData - Dynamics 365 
Dynamics 365 Talk
Custom number sequence in D365FO 
d365fo number sequence setup
setup number sequence d365
create new number sequence d365
number sequences d365
d365 f&o number sequence
what is number sequence
number sequence identifier
number sequence code
How to Create Number Sequence in D365 FO
How to Create Number Sequence in Microsoft Dynamics 365 for Finance and Operations