web
You’re offline. This is a read only version of the page.
close
Skip to main content
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. 
I have the same question (0)
  • 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.

  • Suggested answer
    Arjun Anand Profile Picture
    200 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.
  • MCJordan Profile Picture
    45 on at
    RE: Custom No. Series

    Thank you Arjun this worked. :-)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,255

#2
Sumit Singh Profile Picture

Sumit Singh 2,665

#3
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,401

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans