web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Make Fields Mandatory in Configuration Package

(8) ShareShare
ReportReport
Posted on by 103
Hi All,
 
On Item Master, I want to make few fields as mandatory for item insertion through configuration Package. Creation of Item in bulk is regular activity. 
I have tried using TestField(), NotBlank Property, Adding condition on Insert Trigger or Modify Trigger But none of them throughs error if i insert blank value in a mandatory field.
 
So Can anyone please help with this? 
I came across configuration template but it asks for default value and automatically assigns it which will not work in my case.
I have the same question (0)
  • Suggested answer
    DAnny3211 Profile Picture
    11,421 Super User 2026 Season 1 on at
    Hi,
    This is a common challenge when using **Configuration Packages** in Business Central, as they are designed primarily for data import—not for enforcing validation logic like mandatory fields.
    Here are a few suggestions to help enforce mandatory fields during item creation via configuration packages:
    ### 1. **Use Table Triggers with `Error()` Instead of `TestField()`**
    `TestField()` only throws an error if the field is not initialized, but it doesn’t always behave as expected during imports. Instead, use the `OnInsert` or `OnBeforeInsertEvent` trigger with explicit `Error()` calls:
    ```al
    if IsBlank("YourField") then
        Error('Field "YourField" is mandatory.');
    ```
    Make sure this logic is in a **codeunit subscriber** to avoid interfering with standard insert logic.
    ### 2. **Use a Validation Codeunit in the Package**
    You can attach a **validation codeunit** to the configuration package. This codeunit can include logic to check for blank fields and raise errors accordingly. This is more reliable than relying on field properties alone.
    ### 3. **Post-Import Validation**
    If validation during import is too restrictive, consider allowing the import and then running a **validation report** or **batch job** that flags or blocks incomplete records before they’re used in transactions.
    ### 4. **Avoid Default Values in Templates**
    As you mentioned, configuration templates assign default values, which can mask missing data. If you want to enforce manual entry, avoid using templates for those fields or set the default to a clearly invalid placeholder (e.g., “REQUIRED”).
    Let me know if you’d like help writing the validation codeunit or event subscriber!
    Best regards,  
    Daniele
  • VG-27060905-0 Profile Picture
    103 on at
    Thank You Daniele,
     
    I have tried using table triggers with error() but it is causing problem while creating item from business central page as there are multiple fields i need to make mandatory on the basis of item type.
     
     
    So can you please suggest an event subscriber for configuration package to write the validation code.
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,803 Super User 2026 Season 1 on at
     
    You must use "OnBeforeInsertEvent".
     
    for exemple :
    [EventSubscriber(ObjectType::Table, Database::Item, 'OnBeforeInsertEvent', '', false, false)]
    procedure OnBeforeInsertItem(var Rec: Record Item; var xRec: Record Item; RunTrigger: Boolean)
    begin
        if Rec."Is Imported From Config Package" then begin
            if Rec."Base Unit of Measure" = '' then
                Error('Base Unit of Measure is mandatory.');
            if Rec.Description = '' then
                Error('Description is mandatory.');
            // Add other mandatory fields here
        end;
    end;
    Best regards,
     
  • Suggested answer
    Sohail Ahmed Profile Picture
    11,177 Super User 2026 Season 1 on at
    You're right that standard validations like TestField() don’t trigger during Configuration Package imports. To handle this, you can use the OnBeforeInsertEvent on the Item table (Item.OnBeforeInsertEvent) to validate required fields before the record gets inserted — even during config package imports.
     
    In that event subscriber, you can check if fields like "Base Unit of Measure" or "Item Category Code" are blank, and raise an error if they are. This method works better than relying on TestField() in the insert trigger, which is often bypassed.
     
    Want a sample event subscriber code to get started?
     
    ✅ Mark this answer as verified if it helps you.
     
     
  • Suggested answer
    Jeffrey Bulanadi Profile Picture
    9,121 Super User 2026 Season 1 on at

    Hi,

    Enforcing mandatory fields during configuration package imports is notoriously tricky in BC. The issue stems from how RapidStart bypasses standard validation triggers like OnInsert() and OnValidate() during bulk imports.

    Here’s what you can try:

    • Use a validation codeunit that runs post-import to check for blank values. You can trigger this manually or via a job queue. This gives you control without relying on native triggers.
    • Consider building a custom import page that wraps the configuration logic and includes TestField() calls before insertion. This works well if you want to enforce rules without modifying the base table.
    • If you're open to extensions, the Mandatory Fields Accelerator by Prodware lets you define required fields across key tables (including Item) and blocks inserts when values are missing. It’s designed for exactly this use case.
    • Avoid relying on NotBlank or ShowMandatory properties — they’re UI-only and don’t enforce validation during background imports.
    • As a last resort, you can use XMLPorts with embedded validation logic. They’re more verbose but give full control over field-level checks.


    Helpful References
    Mandatory Fields Accelerator – Prodware Guide
    How to Make a Field Mandatory – Dynamics 365 Lab
    Community Thread on Mandatory Fields in Config Packages


    If you find this helpful, feel free to mark this as the suggested or verified answer.

    Cheers
    Jeffrey

  • Suggested answer
    Jainam M. Kothari Profile Picture
    16,696 Super User 2026 Season 1 on at
  • Suggested answer
    Sumit Singh Profile Picture
    11,795 Super User 2026 Season 1 on at
    Recommended Solution: Use OnValidate or OnInsert with DataClassification and ValidateFieldGroup
    To enforce mandatory fields during Configuration Package import, you need to customize the table using AL code. Here's how:
    1. Create a Custom Codeunit for Validation
    Use a Codeunit that runs after the data is imported but before it’s applied. This can be triggered manually or as part of a post-processing step.
    2. Use OnInsert or OnBeforeInsertEvent with Explicit Checks
    In your Item table extension, override the OnInsert or use OnBeforeInsertEvent to check for blank fields:
    ⚠️ This will only work if the Configuration Package is set to not skip triggers. Ensure the "Skip Table Triggers" option is unchecked in the package.
    3. Use ValidatePackage or ApplyData with Custom Logic
    You can also create a custom validation Codeunit that runs after import but before applying data. This gives you full control to loop through staged records and validate them.
    Here’s a sample AL extension that enforces mandatory fields during Item creation via Configuration Package in Business Central. This approach uses an event subscriber to validate fields during the OnBeforeInsertEvent, ensuring that even bulk imports trigger the validation logic.

    Step-by-Step AL Code
    1. Create a Table Extension for Item
    You don’t need to modify the base table directly. Instead, subscribe to the insert event.
    tableextension 50100 ItemExtension extends Item
    {
        // No need to add fields here unless you're adding custom fields
    }

    2. Create a Codeunit with Event Subscriber
    codeunit 50101 ItemValidationSubscriber
    {
        [EventSubscriber(ObjectType::Table, Database::Item, 'OnBeforeInsertEvent', '', false, false)]
        local procedure ValidateMandatoryFields(var Rec: Record Item; RunTrigger: Boolean)
        begin
            if Rec."Base Unit of Measure" = '' then
                Error('Base Unit of Measure is mandatory.');

            if Rec."Inventory Posting Group" = '' then
                Error('Inventory Posting Group is mandatory.');

            if Rec."Item Category Code" = '' then
                Error('Item Category Code is mandatory.');

            // Add more validations as needed
        end;
    }

    ⚠️ Important Configuration Package Settings
    To ensure this works during import:
    • Go to Configuration Packages → Select your package.
    • Click Tables → Select the Item table.
    • Ensure "Skip Table Triggers" is unchecked.
    • This ensures that OnBeforeInsertEvent is triggered during import.
    🧪 Optional: Add a Post-Import Validation Tool
    If you want to validate after import (e.g., for audit), you can create a Validation Page or Report that scans for items with missing mandatory fields and flags them.
    Note: This response was created in collaboration with Microsoft Copilot to ensure clarity and completeness. I hope it helps to some extent.
    Mark the Answer as Verified if this is Helpful.
  • VG-27060905-0 Profile Picture
    103 on at

    Thank you, everyone!

     

    However, I’ve encountered an issue with using the OnBeforeInsertEvent or OnBeforeModifyEvent when creating items manually from the Items page. I have about 15 fields that need to be mandatory, and until all of them are filled, I keep receiving errors during data entry. This leads to a poor user experience.

     

    While I could implement a custom uploader or use an XMLport as a workaround, I’d prefer to treat that as a last resort.

  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,803 Super User 2026 Season 1 on at
     
    Is your issue fixed ? If yes, then please verify the answers that helped
  • Suggested answer
    VG-27060905-0 Profile Picture
    103 on at
    I am now using a Temporary table to make fields mandatory and then inserting them to item table using uploaders as all the suggestion were giving in some cases.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,260 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,515 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,373

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans