Skip to main content

Generate Number Series from one Company and use it in another company

When dealing with Number Series where the Intercompany Documents are created automatically using the code, using standard number series generation Codeunits cause problems. In this blog, I'll be explaining why this issue is caused and how to resolve such issues.

  • Microsoft Dynamics NAV / Business Central
  •  VS Code 
  • AL Language Extension

  • Issue:
Let's say I'm logged in as user of Company B. When I create Sales Order in current company, I need to create Purchase Order in target company say Company A.
When I use the Number Series declared on Company B's Purchase and Payable Setup for Purchase Order, the system either gives an error that Number Series does not exist or number generated is out of sync as Number Series are stored on Per Company basis. This results in overlapping of next PO number to be generated.

  • Cause of the Issue:
NoSeriesManagement Codeunit 396 works only with the No. Series for the current company. Because of this if the No. Series with same code is present, the system generates No. Series which is completely different than that of the Company B. Also, there is no synchronization mechanism available out of the box to do the Intercompany No. Series sync.

Create the same Number Series in both the entities:
The Number Series is to be created in the primary company(Company A). The code mentioned below will automatically create the number series in the target company(Company B) from Company A.

Code to automatically Insert No. Series 

Prior to Creating Number Series

After the creation of Number Series

Modifying the Number Series back to Company A from Company B:
Using this function, I modified the newly created number series back to the original company.

Declare the Number Series and CompanyName to be used in Setup:
In Company A, I've created Number Series in General Ledger Setup. Using this No. Series declared in Company A use this No. Series to create Purchase Order in the same company through Company B.

Use ChangeCompany() to the target company(Company B) where you want to create the document. Modify the Number Series Line from Company B in Company A using a function.

Code to copy number series from Company A to Company B, generate the new number series and modify the number series back in Company A from Company B

In this way, we can generate a number series for one company from another company.


Popular posts from this blog

Managing with Multiple Legal Entity Data in Microsoft Dynamics NAV / Business Central

Problem Statement:
Well, my client is a Trader of Oils & Fatty Acids and has multiple legal entities to perform various sets of operation on the TRUCK-LOAD(a.k.a. Load). One legal entity creates the Load and schedules it, while another manages with the freight requirements. The information is not shared between both the legal entities. Thus, we need to store the data separately.

For Microsoft Dynamics NAV:
- C/Side Development Environment
- Multiple legal entity(Company) setup

For Microsoft Dynamics Business Central:
- Visual Studio Code
- AL Language Extension
- Multiple legal entity(Company) setup

Solution Design:
1. Create two Tables say LoadCompany1 and LoadCompany2 with same fields
2. Set DataPerCompany property is to TRUE on both the tables.
3. In NAV/ BC, there are common tables but the data into the tables are different. Thus, the system has to manage different version for a single table based on an entity that you're currently working on.
In this case, I n…

Creating APIs in Business Central - 1

While writing a blog on Automated Testing in Business Central, I was going through sample apps provided by Microsoft and realized that the complexity is nowhere close to what examples Microsoft has provided on In this blog, I will try to explain how APIs work and how to be creative with the implementation. Also, an API which were in beta are finally out with version V1.0 in the April 2019 release let's see some important key things from development aspects.
This blog is going to be theoretical one kindly bear with me.

Microsoft Dynamics Business Central (SaaS)VS Code( Language Extension( V1 from Business Central On-Premise DVD
Books & References:
API V1 from Business Central On-Premise DVDAPI(V1.0) for Business Central (Click Here)API(Beta) for Business Central (Click Here)

Key Requirements:
API source table must have an Id(GUID) field per record for m…