Options

how to get the no. series automaticaly from the code

ntnt Member Posts: 160
Hi,

someone knows how to get the no. series automaticaly from the code?

for example if i got the the no. textbox hide, i got to get the no. from the code.

thanks.

Comments

  • Options
    Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    I guess you want to know how to create an automatic numbering, based on a No. Series?

    Have a look at the code of eg. the table 27 Item. You find code in the OnInsert-trigger:
    IF "No." = '' THEN BEGIN
      GetInvtSetup;
      InvtSetup.TESTFIELD("Item Nos.");
      NoSeriesMgt.InitSeries(InvtSetup."Item Nos.",xRec."No. Series",0D,"No.","No. Series");
    END;
    

    and the Validate-trigger of the field "No.":
    IF "No." <> xRec."No." THEN BEGIN
      GetInvtSetup;
      NoSeriesMgt.TestManual(InvtSetup."Item Nos.");
      "No. Series" := '';
    END;
    

    In the table Inventory Setup (variable InvtSetup), the field "Item Nos." is used to store the No. Series which need to be used for the automatic numbering of the items.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • Options
    ntnt Member Posts: 160
    thanks.

    i want to insert a record to in a table from a codeunit, so i dont have de xRec variable, what i got to put instead?
    and i dont have the OnInsert trigger.
  • Options
    Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    But you have an OnInsert-trigger on the table, so write your code there and execute the OnInsert-trigger from the codeunit:
    myTableVar.INSERT(TRUE);
    
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • Options
    ntnt Member Posts: 160
    where in the code i can get the last number used or the next nember for use...the number that i got to insert into the table for the next record?
  • Options
    Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    This is already done in codeunit 396 NoSeriesManagement. The function InitSeries will call the function GetNextNo, which finds out the next number to be used.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • Options
    ntnt Member Posts: 160
    so, in my codeunit i only have to run the OnInsert-trigger of the table and then put the value of the fields that i want, and then record.modify. right?
  • Options
    Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    That is right, if you have some code in the OnInsert-trigger of the table, as shown above.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • Options
    ntnt Member Posts: 160
    OnRun()
    PurchHeader.INSERT(TRUE);
    PurchHeader."Buy-from Vendor No." := '01.000007';
    PurchHeader.MODIFY;
    

    in teh OnInsert() of the table:
    OnInsert()
    PurchSetup.GET;
    
    IF "No." = '' THEN BEGIN
      TestNoSeries;
      NoSeriesMgt.InitSeries(GetNoSeriesCode,xRec."No. Series","Posting Date","No.","No. Series");
    END;
    
    InitRecord;
    
    IF GETFILTER("Buy-from Vendor No.") <> '' THEN
      IF GETRANGEMIN("Buy-from Vendor No.") = GETRANGEMAX("Buy-from Vendor No.") THEN
        VALIDATE("Buy-from Vendor No.",GETRANGEMIN("Buy-from Vendor No."));
    
    "Doc. No. Occurrence" := ArchiveManagement.GetNextOccurrenceNo(DATABASE::"Purchase Header","Document Type","No.");
    
    DimMgt.InsertDocDim(
      DATABASE::"Purchase Header","Document Type","No.",0,
      "Shortcut Dimension 1 Code","Shortcut Dimension 2 Code");
    
    IF WebSite.FIND('-') THEN
      SynchMgt.InsertPurchaseHeader(Rec);
    


    This don´t work.
  • Options
    Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    This works:
    OnRun()
    PurchHeader.INIT;
    PurchHeader."Document Type" := PurchHeader."Document Type"::Order;
    PurchHeader.INSERT(TRUE);
    PurchHeader."Buy-from Vendor No." := '01.000007'; 
    PurchHeader.MODIFY;
    
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • Options
    ntnt Member Posts: 160
    it work.
    thanks :D

    i always got to define the type of document?
  • Options
    Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Of course: how else can Navision know what Number Series you want to use (Quote, Order, Invoice).
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
Sign In or Register to comment.