Skip to main content

Command Palette

Search for a command to run...

Auto-Populate Item ID by Scanning Barcode in Dynamics 365 Finance & Operations (X++ Tutorial)

Updated
2 min read
Auto-Populate Item ID by Scanning Barcode in Dynamics 365 Finance & Operations (X++ Tutorial)
F
Dynamics 365 Finance and Operations Developer

When working with Transfer Order / Sales Order / Purchase Order in Dynamics 365 F&O, the standard behavior requires the user to manually select the Item ID every time they add a new line.

But in many warehouses, users simply want to scan the barcode and automatically have the related item appear on the line — saving time and reducing manual errors.

Recently, I implemented this exact requirement:

When a user scans the item barcode on the Transfer Order line, the system should automatically fetch the Item ID linked with that barcode and populate the line.

To achieve this, I created a custom barcode field on the InventTransferLine table named MZNFRItemBarCode, and then added logic to validate the barcode and populate the ItemId automatically.

Below is the code I used.

X++ Code — Auto Populate Item ID By Scanning Barcode

[ExtensionOf(tableStr(InventTransferLine))]  
 final class MZNFRInventTransferLine_Extension  
 {  
   public boolean validateField(FieldId _fieldIdToCheck)  
   {  
     boolean ret = next validateField(_fieldIdToCheck);  
     switch (_fieldIdToCheck)  
     {  
       case(fieldNum(InventTransferLine, MZNFRItemBarCode)):  
       
         InventItemBarcode InventItemBarcode;  
         
         select * from InventItemBarcode  
         where InventItemBarcode.itemBarCode == this.MZNFRItemBarCode;  
         
         if(InventItemBarcode.itemId)  
         {  
           this.ItemId = InventItemBarcode.ItemId;
           //call ItemId modified method here to follow system behaviour.
         }  
         else  
         {  
           ret = checkFailed("ItemId not found with this barcode.");  
         }  
       break;  
     }  
     return ret;  
   }  
 }  

How This Code Works

  1. 1. Custom Field for Barcode

    I added a custom field MZNFRItemBarCode to InventTransferLine.
    This is where the scanned barcode gets stored.

  2. Overriding validateField

    The validateField() method is triggered when the user enters data in a field.
    So when the barcode field is filled (e.g., by a scanner), this method runs.

    3. Lookup in InventItemBarcode Table

    The code searches the InventItemBarcode table:

    • If the barcode exists → get the associated ItemId

    • If the barcode is invalid → show an error

  3. Auto-Fill the Item ID

    When a valid barcode is found, the system automatically sets:

    this.ItemId = InventItemBarcode.ItemId;
    

    Thus, the transfer order line gets created without manual selection.

Result

✔ User scans the barcode
✔ Item ID automatically populates
✔ Faster data entry
✔ No manual item selection
✔ Reduced errors in warehouse operations

Form Customization

Part 2 of 2

This series explores form customization in Microsoft Dynamics 365 Finance and Operations, covering practical techniques and real-world scenarios. It is designed to help developers understand how to extend, modify, and enhance forms using best practices. From basic concepts to advanced customization methods, each post provides step-by-step guidance to build efficient and maintainable solutions in D365FO.

Start from the beginning

COC of modifiedField in X++

Chain of Command (CoC) is the standard way to extend method behavior in Dynamics 365 F&O — no overlayering, no merge conflicts, fully upgrade-safe. How It Works CoC lets you wrap around any method in

More from this blog

D

Dynamics 365 Finance & Operations

2 posts

This blog shares practical insights on Microsoft Dynamics 365 Finance & Operations (D365FO) development. Readers can expect tutorials, coding tips, and real-world solutions using X++. Topics include customizations, extensions, data entities, debugging, and integrations. It is designed for both beginners and experienced developers looking to build efficient and scalable D365FO solutions.