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

Popular posts from this blog

Amount In Words in Navision / Business Central

Hi Guys, In this article, we will see how to display amount in words in Microsoft Dynamics Business Central. Here, I am taking an example of Report object  which is widely used in Navision for converting decimal amount field into words. Procedure :-  Step-1 Declare the following Global Variables :         RepCheck:  Report  "Check";         NoText:  array [ 2 ]  of   Text ;         AmountInWords:  Text ; where, (1) RepCheck is a variable of  Report DataType Named as " Check " which is 1401. (2) NoText is a variable of DataType " Text " with array Dimension value as 2 which is defined as shown above. (3) AmountInWords is a variable of DataType " Text " which will store final result of amount in words. Step-2 Now, add the following code in OnAfterGetRecord() trigger of DataItem containing that decimal field value. So in my custom Purchase Order Report, i am adding code in the Purchase Header (DataItem) - OnAfterGetRecord() trigger.   trigger  OnA

Flow Custom field to G/L Entry and other Posted tables : From Purchase Order to Posted Purchase invoice

Hi Readers, In this blog we will see how we can transfer data from " Purchase Header" to "Purchase Invoice Header" & "G/L Entry" table in Business Central. In this example, will create "Remarks" field on Purchase Header table and after posting, flow it to Purchase Invoice Header & G/L Entry tables: Firsly, create required fields ("Remarks") in below mentioned tables by creating table extensions: Purchase Header (38) Purch. Inv. Header (122) Gen. Journal Line (81)  G/L Entry (17) For the Purch. Inv. Header table, you can just create copy the field from purchase header and paste it in  Purch. Inv. Header  table. If the field ID No. is same for that field for both the tables then you don't have to code i.e, it automatically transfer that field data from Purch. Header to Purch. Inv. Header . Step-(1)   tableextension   50104  "Purchase Header Ext"  extends  "Purchase Header" {      fields     {         

Calculate Date : Using Date Formula and CalcDate Function in Navision/BC

 Hi Everyone, In this article we will see how we can Calculate Date by adding and subtracting No. of Days / Months based on CalcDate and DateFormula datatype. Here, I define three variables required for: (1) " No of Days " -  To define No. of Days / Months as required. You can also use these units denoted as: <Unit> = D | WD | W | M | Q | Y (D=day, WD=weekday, W=week, M=month, Q=quarter, Y=year). (2) " From Date " and " To Date "  Date type Variables to store calculated date in it. page   50103  "Date from Date Formula" {     PageType = Card;     ApplicationArea = All;     UsageCategory = Administration;     SourceTable =  Integer ;      layout     {          area( Content )         {              group( General )             {                  field( "No. of Days"; "No. of Days" )                 {                     ApplicationArea = All;                 }             }         }     }      actions     {          area