Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Custom No. Series

(0) ShareShare
ReportReport
Posted on by 45

I am trying to create a new No. Series.  I've added a field to the Sales & Receivable Setup table 'Price Model' and gave it a value of 'MODEL' for the code.  I've also added the No. Series info for MODEL (beginning, ending No. etc..).  I have a Card Page for  Price Models and now I would like to create new Model No.'s in the app when Add/Inserting records. I've used the same procedures as occurs on the Sales Header table - GetSalesSetup and NoSeriesMgt etc... but I am not successful.  I am wondering if anyone has created a custom No. Series process or if there is sample code I can reference.   I think I am missing something in regards to retrieving the value of the code from Sales & Receivable Setup table.  Below is my code for Model No. OnValidate, code from OnInsert, and supporting local Procedures: 

 field(1; "Model No."; Code[20])
        {
            CaptionML = ENU = 'Model No.';
            Editable = true;
            trigger OnValidate();

            var
                NoSeriesMgt: Codeunit NoSeriesManagement;
                DefaultNoSeriesCode: Code[20];
            BEGIN
                IF "Model No." <> xRec."Model No." THEN BEGIN
                    GetSalesSetup;
                    NoSeriesMgt.TestManual(DefaultNoSeriesCode);
                    "Model No." := DefaultNoSeriesCode;
                 END;
            end;
        }


    trigger OnInsert();

    var
        NoSeriesMgt: Codeunit NoSeriesManagement;
        DefaultNoSeriesCode: Code[20];
        NewDate: Date;
        OldNoSeriesCode: code[20];
        NewNoSeriesCode: Code[20];
      BEGIN
        IF "Model No." = '' THEN
            GetSalesSetup();
        NoSeriesMgt.InitSeries(DefaultNoSeriesCode, OldNoSeriesCode, NewDate, "Model No.", NewNoSeriesCode);
    end;


    local procedure GetSalesSetup()
    var
        SalesSetup: Record "Sales & Receivables Setup";
        NoSeriesMgt: Codeunit NoSeriesManagement;
        DefaultNoSeriesCode: Code[20];

    begin
        SalesSetup.Get();
        NoSeriesMgt.TestManual(DefaultNoSeriesCode);
        "Model No." := DefaultNoSeriesCode;
        OnAfterGetSalesSetup(Rec, SalesSetup, CurrFieldNo);
    end;

    local procedure OnAfterGetSalesSetup(ModelHeader: Record "Price Model Header"; var SalesReceivablesSetup: Record "Sales & Receivables Setup"; CalledByFieldNo: Integer)
    begin
    end;

 
Thank you in advance for any guidance you may provide. 
  • MCJordan Profile Picture
    45 on at
    RE: Custom No. Series

    Thank you Arjun this worked. :-)

  • Suggested answer
    Arjun Anand Profile Picture
    198 on at
    RE: Custom No. Series

    Hi,

    Please try this below code:

        procedure GetSalesSetup()
        var
            SalesSetup: Record "Sales & Receivables Setup";
            NoSeriesMgt: Codeunit NoSeriesManagement;
            //DefaultNoSeriesCode: Code[20];        
        begin
            SalesSetup.Get();
            DefaultNoSeriesCode := SalesSetup."Model No.";
            NoSeriesMgt.TestManual(DefaultNoSeriesCode);
            //"Model No." := DefaultNoSeriesCode;
            OnAfterGetSalesSetup(Rec, SalesSetup, CurrFieldNo);
        end;
        trigger OnInsert()
        var
            NoSeriesMgt: Codeunit NoSeriesManagement;
            NewDate: Date;
            OldNoSeriesCode: code[20];
            NewNoSeriesCode: Code[20];
        BEGIN
            IF "Model No." = '' THEN
                GetSalesSetup();
            NoSeriesMgt.InitSeries(DefaultNoSeriesCode, OldNoSeriesCode, NewDate, "Model No.", NewNoSeriesCode);
        end;
    Note: Declare "DefaultNoSeriesCode" variable as global instead of local on both the functions
    Thanks.
  • Brad_P Profile Picture
    1,549 on at
    RE: Custom No. Series

    In the snippet provided you do not appear to be setting the DefaultNoSeriesCode variable. The validation of the No. is to confirm if the user can manually enter a number. You would not set the number to something different in the validation of the field (you'd also probably need to do a rename if it is the key). In the oninsert of the table is more appropriate for setting the value.

    OnInsert()
    IF "No." = '' THEN BEGIN
    SalesSetup.GET;
    SalesSetup.TESTFIELD("Model Nos.");
    "Model No." := NoSeriesManagement.GetNextNo(SalesSetup."Model Nos.",Today,true);

    END;

    The Customer Table is a better example for you to model.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,278 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,002 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans