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;

Wednesday, April 10, 2019

How to remove password from Windows Server 2016 for Dynamcis 365 Finance & Operations Server?

Hi,

I was facing this issue from a long time, to resolve this error I followed below blog at

https://social.technet.microsoft.com/Forums/en-US/78ed9550-be5d-4d72-8ad5-4255e176e263/how-would-i-remove-the-password-on-server-2012?forum=TechnetSandboxForum


From the Start screen, type netplwiz. The command for netplwiz, aka the User Accounts Control Panel, appears in the search results in the left pane. Click that command.
In the User Accounts Control Panel, select the account you wish to use to log in automatically.
Click off the check-box above the account that says "Users must enter a user name and password to use this computer." Click OK.
Enter your password once and then a second time to confirm it. Click OK.
Restart Windows. Windows now bypasses the lock screen and the log-in screen to automatically take you to the Start screen.

Click on Boolean
Click Apply and enter your domain password.