Skip to main content

How to Setup Custom No. Series in Business Central / Navision

Hi Everyone,

In this blog we will see how we can setup multiple No. series on Customized / developed features. 

In this example, i have Setup No. Series on Employee Detail Card which is my customized page and by clicking on Assist Edit button you can see all No. series attached on Setup with their relationships: 

Demonstration:-

Step-(1) Create required No. Series in the No. Series and then Setup a relationship between them.

No. Series List

Step-(2) Human Resource Setup (Table Extension) >> Create a new field on HR Setup which has Table relation as No. Series Table:

tableextension 50101 "Human Resource Setup Ext" extends "Human Resources Setup"
{
    fields
    {
        // Add changes to table fields here
        field(50000; "Employee Code Nos."; code[20])
        {
            DataClassification = ToBeClassified;
            TableRelation = "No. Series";
        }
    }
}

Step-(3) Then add No. Series field on table with Table Relation - No. Series Table and add code on OnValidate trigger, OnInsert Trigger and Create a new procedure "AssistEdit_EmpNoSeries" which is used to select required series among multiple ones:

table 50100 "Employee Details"
{
    DataClassification = ToBeClassified;
    fields
    {
        field(1; "Employee Code"; Code[20])
        {
            DataClassification = ToBeClassified;
            trigger OnValidate()
            begin
                IF "Employee Code" <> xRec."Employee Code" THEN BEGIN
                    Rec_HRSetup.GET;
                    NoSeriesMgt.TestManual(Rec_HRSetup."Employee Code Nos.");
                    "No. Series" := '';
                    NoSeriesMgt.SetSeries("Employee Code");
                END;
            end;
        }
        field(2; "Employee Name"; Text[100])
        {
            DataClassification = ToBeClassified;
        }
        field(3; "Designation"; Option)
        {
            DataClassification = ToBeClassified;
            OptionMembers = " ","Associate","Consultant","Manager","Director";
            OptionCaption = ' ,Associate,Consultant,Manager,Director';
        }
        field(97; "No. Series"; Code[20])
        {
            DataClassification = ToBeClassified;
            TableRelation = "No. Series";
        }
    }
    keys
    {
        key(PK; "Employee Code")
        {
            Clustered = true;
        }
    }
    procedure AssistEdit_EmpNoSeries()Boolean
    var
        HRSetup_Rec: Record "Human Resources Setup";
        NoSeriesManagement_CU: Codeunit NoSeriesManagement;
    begin
        HRSetup_Rec.Get();
        HRSetup_Rec.TestField("Employee Code Nos.");
        if NoSeriesManagement_CU.SelectSeries(HRSetup_Rec."Employee Code Nos."
        , xRec."No. Series", "No. Series"then begin
            NoSeriesManagement_CU.SetSeries("Employee Code");
            exit(true);
        end
    end;

    var
        Rec_HRSetup: Record "Human Resources Setup";
        NoSeriesMgt: Codeunit NoSeriesManagement;

    trigger OnInsert()
    begin
        IF "Employee Code" = '' THEN BEGIN
            Rec_HRSetup.GET;
            Rec_HRSetup.TESTFIELD("Employee Code Nos.");
            NoSeriesMgt.InitSeries(Rec_HRSetup."Employee Code Nos."
            , xRec."No. Series", 0D, "Employee Code", "No. Series");
        END;
    END;
}

Step-(4) Now add code on  AssistEdit trigger of page as shown below:

page 50102 "Employee Details Card"
{
    PageType = Card;
    ApplicationArea = All;
    UsageCategory = Administration;
    SourceTable = "Employee Details";
    layout
    {
        area(Content)
        {
            group(General)
            {
                field("Employee Code"; "Employee Code")
                {
                    ApplicationArea = All;
                    trigger OnAssistEdit()
                    begin
                        if AssistEdit_EmpNoSeries() then
                            CurrPage.Update();
                    end;
                }
                field("Employee Name"; "Employee Name")
                {
                    ApplicationArea = All;
                }
                field(Designation; Designation)
                {
                    ApplicationArea = All;
                }
            }
        }
    }
}

Result :-  This is how No. Series comes up on Employee Detail Card Page:


Note:- For single No. Series you can skip AssistEdit procedure & trigger Code.

I hope this will help you to setup custom no. series.

Stay connected for more articles:)

Comments

  1. Thanks Kunal, you've saved me banging my head against a wall today :)

    ReplyDelete
    Replies
    1. Welcome dear..Happy to hear that it helps you!!

      Delete

Post a Comment