Showing posts with label Dynamics 365 Business Central. Show all posts
Showing posts with label Dynamics 365 Business Central. Show all posts

Saturday, April 27, 2019

How to publish your own Event in Business Central using AL Code?

Hi,

Publishing your own event means in a scenario where you are not able to find standard events , you can also define your event and publish it for use.

For Example:

In Job Journal Line page you have no event in posting date field.

Lets understand this exercise :

Step 1 :

Create a new Code unit and type teventint

Type your procedure Name and Parameters inside the procedure.


codeunit 50101 JobJournalLinePublisher
{
trigger OnRun()
begin

end;

[IntegrationEvent(true, true)]
procedure OnAfterValidatePostinDateinJobJournalLine(VAR JobJournalLine: Record "Job Journal Line"; var PostDate: Date);
begin

end;

var
myInt: Integer;
}

Step 2.  Define the place where you want to call this Publisher Event.

For me I need it on Page Job Journal Line After validation of No. Field.

pageextension 50100 MyExtension extends "Job Journal"
{
layout
{
// Add changes to page layout here
modify("No.")
{
trigger OnBeforeValidate();
var
Publisher: Codeunit 50101;
begin
Publisher.OnAfterValidatePostinDateinJobJournalLine(Rec, Rec."Posting Date");
end;
}

}

actions
{
// Add changes to page actions here
}

var
myInt: Integer;
}

Screen for reference:

Step 3. Define the Procedure defination and Subscribe.

codeunit 50102 JobJournalLineSubscribers
{
EventSubscriberInstance = StaticAutomatic;

[EventSubscriber(ObjectType::Codeunit, Codeunit::JobJournalLinePublisher, 'OnAfterValidatePostinDateinJobJournalLine', '', true, true)]
procedure OnAfterValidatePostinDateinJobJournalLine(VAR JobJournalLine: Record "Job Journal Line"; var PostDate: Date);
begin
JobJournalLine.VALIDATE(Description, JobJournalLine.Description + ' ' + FORMAT(PostDate));
end;
}

Screenshot for reference:

I hope with this reference you can define your own publisher event in business central.

How to subscribe to an Event in Dynamics 365 Business Central?

Hi ,

What is an Event?

An Event is a function provided by Microsoft to help developers for minimizing code in Standard Object for development.

So to identify which event you want to use , first we need to check the standard event available to subscribe. For details of Events you can follow :


How to subscribe to an event in AL Code?

Here I want to update Posting Description field with Vendor Name in Purchase Invoice Page. So I had subscribed to 2 events provided by Microsoft.

Here I had subscribed to events of Object Type Table. You can use Snippet teventsubs

codeunit 50100 CustomCodeunit
{
trigger OnRun()
begin

end;

[EventSubscriber(ObjectType::Table, DATABASE::"Purchase Header", 'OnAfterInitRecord', '', true, true)]
local procedure OnAfterInitRecord(VAR PurchHeader: Record "Purchase Header")
begin
PurchHeader.Validate("Posting Description", PurchHeader."Buy-from Vendor Name");
end;

[EventSubscriber(ObjectType::Table, DATABASE::"Purchase Header", 'OnAfterCopyBuyFromVendorFieldsFromVendor', '', true, true)]
local procedure OnAfterCopyBuyFromVendorFieldsFromVendor(VAR PurchaseHeader: Record "Purchase Header"; Vendor: Record Vendor)
begin
PurchaseHeader.Validate("Posting Description", Vendor.Name);
end;

var
myInt: Integer;

Tuesday, December 4, 2018

How to : Create a Codeunit in AL Visual Studio?

How to create a Codeunit in AL Visual Studio?


How to define Triggers on page?

How to define Option String in AL Language?


How to publish my App in AL via Power Shell?

PS C:\WINDOWS\system32> Import-Module "${env:ProgramFiles}\Microsoft Dynamics 365 Business Central\130\Service\NavAdminTool.ps1"
PS C:\WINDOWS\system32> Publish-NAVApp -ServerInstance BC130 -Path 'C:\Users\BEG-ASSET-026\Documents\AL\ALProject4\Cronus International_Data Types_1.0.0.0.APP' -skipver
ification

Important DataTypeArray in AL visual studio code for Dynamics 365 Business Central

Dear Readers ,

This blog will tell you about new datatypes available in AL language for MS Dynamics 365 business Central.

Arrays :

Arrays are complex variables that contain a group of variables, with the same data type. An array is declared as a variable with:
  • An identifier
  • A data type
  • Elements
  • An index
  • A dimension
An array holds multiple values, and these values are stored in the elements of an array. You can access these values by using the index. The index can also be a value stored in another variable. With this you can create a loop where you increment a certain variable, to loop trough every element in an array.
By using the dimension property, you can define how many dimensions your array will hold.

One-dimensional and multi-dimensional array

When creating a variable of the array data type, you must define upfront how many elements you will have in your array. The most used is the one-dimensional array. This is just a list of elements with the same data type.
We can represent an array as a row of values:
Array Example
To create an array, we can use the following code:
Array Code
To access an element in an array you will need to use the array element syntax:
Array Element Syntax
In the example above, SaleAmount is our identifier, and we are accessing the fifth element in the array. We are setting the value 0 in the fifth element. This would result in:
Array Result
Because there is only one element between the square brackets, this indicates that we are using a one-dimensional array. If we want to have a multi-dimensional array, you would use a comma separated list between the brackets.
A multi-dimensional array can be represented as a table of values:
Multi-Dimensional array
To create an array, we can use the following code:
Create an Array
To create an array, we can use the following code:
Create an Array
To access an element in an array, you will need to use the array element syntax:
Array Element Syntax
In the example above, we are accessing the fifth row and the third column in the array. We are setting the value 0. This would result in:
Array Result

Thursday, November 29, 2018

How to Start customising AL Extension for Dynamics 365 business central?

Dear Readers ,



This post is related with my AL development. Lets start to dive in Business Central to get a real idea.

Step 1. Open Visual Studio Code and Goto View-Command Pallette.

1. Select AL:GO
2. Type the project Name : Social Media
3. Change the Launch.json  file as shown in screen if you are using windows Authentication.


4. Download the Symbol from View and Command Pallete by typing AL:Download Symbol


5.Once your Symbols are downloaded you can start with real development.

6. Delete Hello World.AL file and create 1 folder with name  Tables to put all tables and create 1 file in it with name SocialMediaExtension.al as shown in screen.


How to Extend existing tables via AL Code in Visual Studio?

1. Type ttable to use code snippet. And change the file as shown in screenshot.


2. Create one more folder Page and Add one more file for SocialMediaCard.al Pages. Publish the Extension to view your ready Extension. If you need some guidance to Publish the extension you can follow my last point of blog LINK.


3. After the Publish you can check your Extension Management Page.


4. Install the Extension and check your Customer Card PAge with new fields where you can enter records for your cutomers.

I hope this blog will help to understand AL Extension and coding link with your projects.