Advertisements

Event driven Programming – Business Central

You can use events to design your application. Below are the benefits of using this model.

  1. You can lower the cost of code modifications and upgrades.
  2. You can customize functionality without modifying the original application.
  3. Your program will react to specific actions or behaviours of original application.

E-2

The following table describes all the different event types:

Event types Description
BusinessEvent Specifies the method to be business type event publisher.
IntegrationEvent Specifies the method to be integration type event publisher.
Global Global events are predefined system events.
Trigger Trigger events are published by the runtime.

You program events in the application to run customized behaviour when they occur.

E-1

What are Events?

A thing that happens. Event is declared by an AL method, which is referred to as event publisher function. Publisher method have only signature only and does not execute any code.

Publisher is the object that contains event publisher methods that declares the event. It serves as hook-up point in application, where subscribers use these points to extend the functionality, without even making any changes to the base application.

Only publishing an event do nothing in application, these events must be raised for subscribers to respond.

Especially Business and Integration type events must be published and raised, you need to create event publisher functions and add them to the objects manually.

Trigger events which occurs on Table & Page operations, are automatically published and raised by system at runtime, so no coding is required to publish them.

Subscriber is an AL method that subscribes to even publisher method, and logic to handle the event is implement.

E-3

Creating an event publisher method to publish business and integration events

Creating event publisher method is similar to other methods you define in AL. In addition some specific properties and few restrictions.

  • Can not include any code except comments.
  • You cannot define return values, variables or text constants.

You can define event publisher in any objects new or in existing objects and of any type of objects like codeunit, page or table.

If you define even as local then it will not be available for subscribers.

[IntegrationEvent(IncludeSender,GlobalVarAccess)]

local procedure MyProcedure()

begin

end;

[BusinessEvent(IncludeSender)]

local procedure MyProcedure()

begin

end;

Feel free to add as much of parameters and of any type as required. However it is advised not to include unnecessary parameters to Business events.

Raising Events

You need to modify the application to raise the event where ever it is needed. You call the event publisher method, same way you call any other methods in AL.

When the execution hits the evet publisher method, all event subscriber method that subscribe to the event are executed. Limitation will be you can not specify the order in which subscriber method will run, subscribers will be picked one at a time and in random order.

E-4

Subscriber Method

You can create new or use existing codeunits to define subscriber methods.

[EventSubscriber(ObjectType::Codeunit, Codeunit::, ‘OnSomeEvent’, ‘ElementName’, SkipOnMissingLicense, SkipOnMissingPermission)]

local procedure MyProcedure()

begin

end;

Add code to the method for handling the event.

Don’t worry at this point we will go through complete process programmatically in our next upcoming posts.

How to find which event to subscribe, and where to write our code.

Similar to earlier days we used Code Coverage, same way we have Event Recorder in Business Central.

Search for Event Recorder in RTC or alternatively you can launch from VS Code from Command Palate AL: Open Events Recorder.

Let’s look at a small example of finding Events.

I want to know what all events hit or available to subscribe when Sales-Order is Re-Opened.

Step-1: Open the Event Recorder and Click on Start.

E-5

Step-2: Perform Sales-Order -> Reopen

Step-3: Click on Stop.

E-6

Step-4: Scan from the list of events that you find suitable, to know how to subscribe to that event you can find AL Code. (Get AL Snippet)

E-7

All the recorded events display in the order they were called. The Event Recorder page provides information on the events that were raised including the details whether the raised events were trigger events or custom events. The custom events are either Business Events or Integration Events.

You can identify the Event types, additionally, you can discover which object types and methods raised the events with the details like calling methods, object types, and object names.

Readiness to Event:

  • Redesign your on prem to an event-based approach in C/AL.
  • This will prove to be best preparation for moving to VS Code AL extension.
  • You will be able to find any issues in your code that you need to refactor.
  • Next step will be to Lift your on prem product to VS Code AL extension.
  • Then extension can be published as a MSDY365 Business Central app.

Now you know about basics of Events. Understand Publisher, Raising Events and Subscribing to Events. Also how to trace and find suitable events to subscribe for your customization over base application.

Before we end the post let’s have a Recap to Events

Publish:

  • Announcement by the application
  • Function without code
  • Exposes the event to the outside

Raise:

  • Specifies exactly when the event happens
  • Call to the Publisher Function

Subscribe:

  • React to the event
  • Must be in codeunit, tableextension or pageextension.

Note: Raise order specified in code, Subscribe order undefined.

We will look into practical approach in our next post.

 

Advertisements

AL Basics – Part 4 [Page]

Today we will see how to create pages in AL.

Before we dive into it lets have some basic concept for Pages.

If you navigate in Navision you may be familiar with page types we have in Navision.

Types of Page

  • Card Page
  • List Page
  • CardPart Page
  • ListPart Page
  • Worksheet Page
  • Document Page
  • RoleCenter Page
  • Confirmation Dialog Page
  • ListPlus Page
  • StandardDialog Page
  • Navigate Page

All above pages are just how we design and use them for specific purpose, I will not go in details what type of page is used for what purpose you can find them in any document or already familiar with.

When we design pages we should have idea of Page Controls

Different Page Controls you have on pages are:

  • Actions
  • Content Area
  • Factbox Area
  • RoleCenter Area

All controls are placed in pages using below arrangement

Type SubType
   
Container Content Area
  FactBox Area
  RoleCenter Area
   
Group Group (Fast Tabs – on Card Pages)
  Repeater (List Pages)
  CueGroup (Rolecenter Pages)
  FixedLayout
  Grid layout
   
Field Data from Table
   
Part Display another Page, Chart, System defined features

Lets understand from below Customer List Page

Pag-1

Let’s create our First Page.

To Create a Page First we will create a File .al.

In Editor we fill type snippet tpage

You will get the options available, select Page of type list, we are going to create List Page.

Pag-2

Basic structure of the Page is given to you as below

Pag-3

Lets create our LoadoutPointList Page on Table Loadout Point table created in previous post.

Pag-4

Similarly we will create a Appointment Calendar Setup List Page, final code as below:

Pag-5

Similarly you can design Card Page Also:

I am not creating Page from scratch but will show you few properties, triggers from standard Page e.g.:- Cost Type Card

Pag-6

PageType you need to define as Card.

For FastTab you need to define group.

Pag-7

Above is the example of few properties for field control on Page.

Pag-8

To add factboxes to the page you define area(factboxes).

Here systempart for Links & Notes is added.

Pag-9

Above is actions to the page. Few properties how to define.

Pag-10

Above is the Page triggers.

Complete code for each objects is not possible to include in post.

But I will give to some tips using which you can explore equivalent AL Code and tryout them.

Suppose you want to see any feature how implemented in Customer Card.

Export that object as text, and convert using txt2al for equivalent al code.

You can refer back to my previous post Quick Start with Extensions for Business Central

Similar method I have explained in this post.

Pag-11

We will explore few more possibilities and Extending to existing Table & Pages in our upcoming post.

 

AL Basics – Part 3 [Table Continued]

In last post we saw basics of how to Create Table and created a Loadout Point Table.

Today we will continue from where we left in previous post. If you missed previous post you can find here AL Basics – Part 2.

We will create one New Table say Working Calendar Time Slot. Since no new concept used in this table so without explanation I will directly share the final structure of this Table. I am using this table in today’s next Table which I will be creating later below.

So here is the structure of this Table.

TAB2-1

Now coming to today’s topic. Creating Field Triggers & Functions.

I will be creating a new table Appointment Calendar Setup.

Here is the structure of same, and explanation follows after screen shot.

TAB2-2

In this Table the Loadout Point field TableRelation to the Loadout Point table that we created in our previous post.

Similarly the field Start Working Hrs. & End Working Hrs. field, OnValidate() trigger is implemented which call to a function/procedure CreateTimeSlot() defined in this table itself.

Field Start Working Days & End Working Days is defined with option type.

When user Enters the Start Working Hrs. & End Working Hrs. we will create the Time Slot for that Location (Loadout Point).

Finally I have created a local procedure in the table, which as per the information entered it creates the Time Slot in Table we created above Working Calendar Time Slot. Also see I have created few local variables to the function of different types. You can see there is no difference in writing the code, it follows same syntax as in our Navision C/AL. Advanced coding options and what’s new will discuss separately in future posts.

Till here we have our basic structure of our Extension. We will see how to design page in our next post.

We will come with more advance points on Table Later as we proceed in completing our Extension. There is lots of things to share on this topic but sometime later in future posts. First Let us cover all Object Types.

Quick Start with Extensions for Business Central

Today I am going to give you a tip for getting started with Extension Building for Business Central.

As AL have newly introduced so it is going to take time to learn and be comfortable with programming using AL codes.

Best way of learning anything is learning by examples. What if we first learn what will be equivalent to actions we perform in Navision designer.

So to demonstrate this I will start with creating a small customization directly in Navision then convert it to Extension.

Are you ready? Let’s start with this exciting journey of 1-2-3 step.

Step 1.

Saving my Base Line Object (Prior to performing any Modification).

In this example I am going to Modify Table – Item & Page Item Card.

Let’s export this two object as FOB, Later we will require this to revert our customization.

Also export this two objects as txt. This we will require in our Extension building process. But need to follow instructions explained in below step, else this file will be rejected by the tool when we try to convert to AL. Follow the process of exporting text file explained after completing the Customizations in Step 3.

Step 2.

I will create one Table 50000 – Product Range as below:

1

Next I will create one List Page on above Table, Page 50000 – Product Range as below:

2

Also will Add Table Property as below to enable Lookup & DrillDown

3

Save your objects.

Now I will add one field to Table Item & Page Item Card as below:

4

5

Now I am done with my all customization and saved my modified & New Objects.

Step 3.

Now we will export these objects All New & Modified into Text File.

But we will not do it from Object designer rather will do it from command prompt.

Preparing for AL Conversion.

Run Command Prompt as Administrator.

Change to RTC folder.

6

Check your folder where you have installed, default location is as one I am using.

You can export all objects in one single file or one file per object. I am exporting one object per file, you can explore command parameter to use accordingly.

I will be using below commands.

First we will create 4 Folders namely Original, Modified, Delta & Result

Note: Make sure ExportToNewSyntax with command parameter is used else txt2al (which we will use below) will reject your files, it is mandatory.

Below command is to export Original objects before modification: (Save in Original Folder)

1. finsql.exe Command=ExportToNewSyntax, File=G:\RND\Txt2ALTest\exportedBaselineObjectsT27.txt, Database=”Demo Database NAV (13-0)”, ServerName=”KSD-DESKTOP” ,Filter=Type=table;ID=27

2. finsql.exe Command=ExportToNewSyntax, File=G:\RND\Txt2ALTest\exportedBaselineObjectsP30.txt, Database=”Demo Database NAV (13-0)”, ServerName=”KSD-DESKTOP” ,Filter=Type=page;ID=30

Below command is for New Objects: (Save in Modified Folder)

3. finsql.exe Command=ExportToNewSyntax, File=G:\RND\Txt2ALTest\exportedNewObjectsT50000.txt, Database=”Demo Database NAV (13-0)”, ServerName=”KSD-DESKTOP” ,Filter=Type=table;ID=50000

4. finsql.exe Command=ExportToNewSyntax, File=G:\RND\Txt2ALTest\exportedNewObjectsP50000.txt, Database=”Demo Database NAV (13-0)”, ServerName=”KSD-DESKTOP” ,Filter=Type=page;ID=50000

Below command is for Modified Objects: (Save in Modified Folder)

5. finsql.exe Command=ExportToNewSyntax, File=G:\RND\Txt2ALTest\exportedModifiedObjectsT27.txt, Database=”Demo Database NAV (13-0)”, ServerName=”KSD-DESKTOP” ,Filter=Type=table;ID=27

6. finsql.exe Command=ExportToNewSyntax, File=G:\RND\Txt2ALTest\exportedModifiedObjectsP30.txt, Database=”Demo Database NAV (13-0)”, ServerName=”KSD-DESKTOP” ,Filter=Type=page;ID=30

Our Next step will be to create DELTA files.

Open Business Central Administration Shell

Import your Microsoft.Dynamics.Nav.Model.Tools Module using below syntax

import-module “C:\Program Files (x86)\Microsoft Dynamics 365 Business Central\130\RoleTailored Client\Microsoft.Dynamics.Nav.Model.Tools.psd1” -force –verb

Execute below Shell Command:

Compare-NAVApplicationObject -OriginalPath G:\RND\Txt2ALTest\Original\*.txt -ModifiedPath G:\RND\Txt2ALTest\Modified\*.txt -DeltaPath G:\RND\Txt2ALTest\DELTA\ -ExportToNewSyntax

7

After this process we will get our Delta files in Delta Folder, this will be input to our next command/tool.

Next we will convert Delta File to AL files.

On Command prompt used above run below command: (This is not Shell Window please make sure)

txt2al –source G:\RND\Txt2ALTest\DELTA\ –target G:\RND\Txt2ALTest\RESULT\

8

Here we will get our *.al files. Which will be used for creating extensions.

Step 4.

Perform clean up to the database.

  1. Import the FOB exported in Step one to restore your original Table 27 & Page 30.
  2. Delete New Created Objects.

Now our database in in original state as before performing customization.

Fresh and Clean Business Central Database without any customizations.

Step 5.

In this step we will create extension in VS Code using above obtained *.al file.

Open VS Code and Press <Ctrl>+<Shift>+<P> and select AL:Go! to create a project Folder

9

Enter your Project Folder and press enter

10

Update your app.json file as below:

Add Name & Publisher, also check available idRange all objects in this project must be in this Range.

11

Update your launch.json file with your server & authentication details accordingly:

12

Remove the HelloWorld.al file created by default by right click and select delete.

Now add your created *.al files

13

You can drag and Drop to your Project Folder.

Now you will get errors, to resolve it we need to download our Symbols from Navision.

To download press <Ctrl>+<Shift>+<P> to open command Pallet and select Al: Download Symbols

14

If your server settings in launch.jason is correct your Symbols will get downloaded.

15

Now let resolve any others errors that may have in your *.al Files.

First I will rename my all Files to meaningful name so that in future it is easy to manage.

To do so, right click the File and select Rename, in my case I have renamed as below:

16

Now we will open each file and perform required action to resolve the errors as below.

After changes don’t forget to save your files.

17

18

19

20

Ensure Object ID you use is within the range of id provided in app.json file. ID is not used in database or any other extensions. Else when you deploy the extension it will give errors, also make sure you give unique object names too.

DataClassification property is not available in Al so we removed it.

Now my all objects are error free, and ready to be packaged.

Step 6.

Now we will Deploy & Test our Extension.

To create a package press <Ctrl>+<Shift>+<P> to open command pallet.

21

You can choose AL:Publish also it will create package and Publish to the server.

Next you choose AL:Publish to deploy your Extension to the Business Central.

You can verify your Extension from Extension Management Page from Navision Client

22

Double click on your extension record to see details:

23

Now let’s see in action our extension.

Open Item Card.

24

Congrats, your First Extension is ready to use.

There is lots of many thing to explain, but in single post everything is not possible. I will come up with basic things and creating Extensions from scratch in some other posts.

It was just a quick idea, as everyone is looking option for upgrade so this information may be handy to plan their next move.

We will learn basics of AL and other fundamental things in our upcoming posts.

Before I close this post will like to share few more details to complete this post.

If you check your Navision you will not find any object or additional fields we added in our extension, then where is my data stored?

Let’s have look in SQL.

25

Item Extension & Product Group table is created with your app id of the extension.

We will discuss in more details about other things in details in our next upcoming posts.

Till then keep learning, and stay safe, take care.

 

Future of Navision is extensions V2?

With the release of Dynamics 365 Business Central a successor of Dynamics NAV, things are going to change. If I am not wrong from year 2020 Modern Development Environment will be the only platform available to developers.

In every NAV upgrades biggest challenge was customizations, since objects are fully accessible to developers, so we customize the solution as we want as a developer spreading unstructured, difficult to maintain, customized code everywhere and in all objects.

The beauty of product is, it is totally customizable and adaptable to customer’s business. Customizing Navision is easy and quick to deploy. C/AL is easy to learn and code.

Due to these heavy customizations and unstructured codes upgrade to new version of the product required long time and efforts. Hard to merge, too much efforts leading to high cost, usually many customer prefer to stay with their current version, and miss new capabilities of product available in future versions of Navision.

With release of NAV 2016 concept of extension was introduced. This introduced the concept of writing code isolated from the core objects and use events to interact with the standard codes. Now create the extension that can be installed or uninstalled any time without affecting the original base layer of the product. We call it extension V1.

These were also developed using C/AL and deployed using PowerShell. But still it always felt like something is missing. Then last year Microsoft came up with release NAV 2018 which introduced second generation of extension, we call it extensions V2.

This introduced completely new development platform based on Visual Studio Code Modern Development Environment. It uses new AL language an evolution of C/AL. Now this will be the future.

Dynamics 365 Business Central platform (on-premise and SaaS) uses this development model. Probably this will be the only development platform available from year 2020.

In Business central base application is now an entire extension based with some system objects in CSIDE, In future release you may not have any more side by side development, you will only be having AL and extensions.

 

So what next?

 

  • We should now concentrate on learning VS Code and AL as in future this will be the only way to modify the application.
  • Now we need to make our self-familiar with the Web Client as Windows Client will be obsolete soon.
  • We should start moving our all customization to extensions.
  • Now we should start thinking in direction of AL type customization rather than old C/AL type coding practice.

 

What do you think?

I will come up with more details as progress in this direction. Till then keep learning and sharing with others.

 

 

 

Important

Most of the contents you find in this blog will be either inherited from MSDN or Navision Developer IT Pro Help. Some places images are also directly taken from these sites. Purpose is simple to try those stuffs and re-produce adding few things as per my understanding to make easy understanding for others and quick reference.

Here nothing under my own brand or authorship of the content. At any point of time we are just promoting Microsoft stuffs nothing personnel with same.

Hope stuffs used here will not violate any copyright agreement with them. In case by mistake or in-intestinally it happens and the Microsoft feels these should not be used Microsoft have full right to inform me about same and will be glad to take down any such content which may be violating the norms.

Purpose is to promote Navision and share with community.

FB Profile

Like FB Page

%d bloggers like this: