This tutorial will explain how to implement Number Series in a new table or add them to existing table. First part of tutorial is focused on creating No. Series columns in tables, middle part of tutorial is focused on coding auomatization of No. Series and last part of tutorial is focused on creating function which will be used to drill down to numbering series line of our specific numbering series.
Another thing, best way for designing and developing NAV is using existing functions and code because they're already tested and probably working without bugs.
Step 1: Creating numbering series columns in a table
In our new / existing table You need to create this two columns (fields) which will be used for storing number series. First field (No.) needs to be created as primary key field.
Please name columns as in next table because of copying functions from other tables, and also this is standard naming policy for No. Columns and Number Series columns in NAV.
To create this fields, go to the object designer and create a new Table / design existing table.
Now our table should look like this.
Step 2: Compile table and add C/AL code
When implementing number series automation, there are some required pieces of code that you must include in your table:
- OnInsert() trigger,
- OnValidate() trigger for No. field,
- AssistEdit function.
Whithout writing New code You can paste it from Sales Header Table and modify it, or decide to write you own code. It's up to you.
Before writing Code You need to create Function AssistEdit in Table C/AL Globals with return value Boolean, which you enter in Locals parameters of function.
After function is created you need to create link to No. Series Setup table for your table and NoSeriesManagement codeunit for automatization of number series which will be explained later in this article.
After table C/AL globals are created, compile table, close it and reopen it in design view.
NOTE: Reason for compiling table is because Rec and xRec still aren't validated by compiler and table data so you need to do so in order to write and compile table later. In case you forget this you need to save your new table without Compiled option, and compile it later through object designer.
Now you can start writing your code and when you're deone with modifying your code your new table should look like this.
Now, lets through every trigger and AssistEdit function and explain what they are going to do:
- OnInsert() trigger. Basicly here we write code which tests value in No. Field and if it's empty it calls our rcdSetup record (C/AL Global variable that links our table with table where we're choosing number series for our table nad form) and test if there is value in field „Br. serija za RC“ which is field developed for setting up number series for this project. If we have previously choosed number series we are calling codeunit NoSeriesManagement (C/AL global NoSeriesMgt) which is inserting next value from No. Series Lines table into No. Series and No. fields.
- No. – On Validate () trigger. Here we write function which tests if value in No. field is equal as one in No. Series Lines table. If it is not, then it sets value of No.Series to blank because of insert automation which is dependent on No. Series fields.
- AssistEdit function. This function is developed for purposes of DrillUp to form of No. Series form based on No. Series data of No. Series field of our table. Basicly it calls for NoSeriesManagement function to validate No. Series. Later, when developing forms and pages, this function will enable us to call No. series window with exact No. series value un field of No. of our form.
Step 3: Creating own numbering series
In our table we have added existing No. Series settings whtough rcdSetup C/AL Global parameter. If yuo want to create new number series setting which will be added to Purchase & Payables Setup. Ofcourse you can add number series setup to any other form.
First step is to create new table field which will be used for our purpose. Best thing is to copy and paste existing field for number series.
Now go to last row of table and paste selected column.
Rewrite Field No. to to match row order.
After modifying row of table be sure to check properties of table and TableRelation parameter which needs to be set to „No. Series“ because we used this value in our based table as value for No. Series relation.
If you decide to change this to another value than you need to update our first table with this value – only in C/AL code.
Step 4: Update C/AL code and C/AL globals in first table
After modification of table, you need to go back to our table and change Record parameter in C/AL globals and in C/AL code replace "Br. serija za RC" with „Implementing Nos.“.
Now our C/AL globals need to look like this:
And C/AL code needs to look like this:
Save the table.
Step 5: Create user interface
Last step in implementing our Number series functionality is to set user interface. This is done with OnAssistEdit() trigger on No. field. This will add new button in form field which will open form with No. seris of our setup table.
Create new card form with form wizzard or page with page wizzard.
Now enter C/AL code to trigger
When developing page change CurrForm with CurrPage and you're set.
Now let's test our form.
Enjoy..