Monday, December 26, 2011

Implementing Nmbering Series

Number series is feature in NAV that allows usage of numbering methods and also allows the application to work the same everythere.

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:

  1. OnInsert() trigger,
  2. OnValidate() trigger for No. field,
  3. 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..

Thursday, December 22, 2011

Deleting Rows from FA Journal Page

Working with new Dynamics NAV 2009 pages can be very frustrating, especially if you are used to using keyboard shortcuts in your work.

Other thing that, in my opinion, is nature of pages which is almost opposite of old classic NAV forms. This is what I've encountered during testing of NAV pages.
In classic NAV lists it was easy to mark rows (selecting rows (CTRL+a) and marking feature which is removed from Pages), but on pages it isn't so.
Despite easy of use and windows features, marking was more or less - the same. But I've encountered some strange issues with deleting marked rows in Fixed Asset Journals.

I've marked all of rows (with keyboard) and tried to delete them, but nothing happened.


In picture above you can see that when I selected all rows cursor came to last row and last column and positioned itself in field as if I'm going to enter data into it.

After some testing I still didn't found root of problem and fixed this issue.

I tried changing type of field and even set Edit parameter of last field to , but it didn't work.
Next I tried to mark them with mouse and then tried to delete rows and this time it worked.