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.

Tuesday, April 9, 2019

How to resolve error 500 while accessing Dynamics 365 Finance and Operations URL

Hi ,
This blog is about an error which I faced during accessing Dynamics 365 Finance & Operations. For more information
I am accessing my D365 Demo environment on my local machine with URL
I was getting error as in screen :


Before reading further if you are also facing the same issue then check below solutions , I hope this will be resolved.



This error cause is

1. Services are not running properly.

There are 3 services which mainly runs D365.

a. Application Helper Service

b. SQL Server Service

c. Microsoft Batch Management

d. Microsoft Data Import

Please restart these 4 services


2. IIS may be stopped. Please goto start of your server and run IIS if its not running then restart.

But if error still exists. Then check event viewer.

I followed below Link to resolve this issue.



Lets start the solution :

Step 1. Check which of the certificates are expired.

Run Windows powershell as ADMINISTRATOR


Run Command:


cd cert:\LocalMachine\My
ls | Select-Object NotAfter,Thumbprint,Subject | Where-Object -Property Subject -like "CN=DeploymentsOnebox.*" | Sort-Object -Property Subject,NotAfter


This will check the expired certificates required to run.

There are 4 certificates needed to run this URL of D365 F&O.

The NotAfter column shows when each of them expires. The Subject column contains descriptive information about certificates. The Thumbprint column contains the key by which the certificate is recognized by the operating system.

Step 2. Please goto start->manage computer certificate->Personnal->Certificates

Find these 4 certificates , double click on these certificates and copy the thumbprint. Remove spaces and make small letters to Capital letters.

Do the same for all 4 certificates in word file.

Step 3. Run this code in powershell to add 120 months to each certificates. you will get cloned copies.

$Thumbprint = (get-childitem -Path 01F93A5974A14DC3B40F1CF0BE78127974187BE5 )
New-SelfSignedCertificate -CloneCert $Thumbprint -NotAfter (Get-Date).AddMonths(120)


Please remove the green marked 40 digits key with your certificates Key.


You can get the cloned certificates in Manage computer certificates. But you need to refresh the certificate folder.


Step 4. Check the updated certificates

ls | Select-Object NotAfter,Thumbprint,Subject | Where-Object -Property Subject -like "CN=DeploymentsOnebox.*" | Sort-Object -Property Subject,NotAfter



Step 5.

Now you see two certificates for each of the certificate types – one with the old validity and thumbprint and one with the new validity (current date + 120 months) and thumbprint.
Now start VisualStudio as administrator and open the following three files in the C:\AOSService\webroot folder:
  1. web.config
  2. wif.config
  3. wif.services.config
Press Ctrl+Shift+H key combination to open Find and Replace dialog. Make sure that you select All Open Documents in the Look in drop-down selection box, so that find and replace action will be applied on all three open files.
Now you will have to repeat the following actions for each pair of certificate types:
  1. In the Find what box enter the thumbnail of the old (expired) certificate.
  2. In the Replace with box enter the thumbnail of the cloned new certificate.
  3. Replace all the occurrences in open files.

After you have done this for all four certificates, save the three config files and close VisualStudio.
Restart your browser and navigate to D365FO. It should start without any problems.





 You can also check this link

Tuesday, December 18, 2018

ERROR : MSDYN365BC - Publish Extension Error - NetFx40_LegacySecurityPolicy is enabled and must be turned off.

How to publish App in Business Central without PowerShell ?

While publishing the app I was getting 2 issues :-

Issue 1 :


It was not getting updated and nothing was happening in Output Window. I had installed it via 

PowerShell and it was working for me fine. But there was a problem we need to install several 

versions of same APP. And it was a very lengthy process.

Issue 2 :


While publishing it was giving me error 

MSDYN365BC - Publish Extension Error - NetFx40_LegacySecurityPolicy is enabled and must be turned off.

Solution:

Step 1 :

Go to this file in Service Folder as Shown in Screenshot. (Remember you need to run your system as administrator)


Step 2. Open File in Notepad and find Runtime and make the property to false as shown.

Step 3. Now Restart your NAV Service and Come to visual studio code in your project.
Press F5 or goto View -> Command Pallete -> AL:Publish
Your extension must be published.

If still its not publishing you can comment below.



Monday, December 10, 2018

What is the TempBlob table and why should we use it?

TempBlob  Record Table in Detail






To help you as a developer when writing code to manage import and export of files, you can use the table TempBlob (99008535).

The TempBlob table contains the following fields:

  • Primary Key (integer)
  • Blob (BLOB)

The TempBlob table contains the following functions:

  • WriteAsText
  • ReadAsText
  • ReadAsTextWithCRLFLineSeparator
  • StartReadingTextLines
  • StartWritingTextLines
  • MoreTextLines
  • ReadTextLine
  • WriteTextLine
  • ToBase64String
  • FromBase64String
  • GetHTMLImgSrc
  • GetImageType
  • GetXMLAsText

You should use this table as a temporary table, by setting the Temporary property on the record variable. This makes sure that changes made to the temporary table are not stored in the database. Examples of how to use the TempBlob table are available in codeunit 419 File Management.

Saturday, December 8, 2018

How to implement Event , Publisher and Subscription in AL Visual Studio Code for Business Central?

Dear Readers ,

Today I got one requirement for using Events , Subscription and Publishers in AL Development

environment. Lets start by creating a new Visual Studio Code.

Step 1. Open Visual Studio Code and create a new project and download symbols. To check this you

can go to my this blog. And follow till Step 8.

Step 2. Create a new file Validations.al and then create a Codeunit using snippet tcodeunit.

Step 3. Create a simple function Using a tprocedure

Step 4. And write a Simple code to find out + in Address field.



Step 5. Then type tEventSub for Event Subscriber structure of code and change the values for

customer table as shown in Screen shot.


Step 6. Publish your extension and install to check the Result Dynamics 365 Business Central.





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

How to define List in AL using visual studio code?

List


The List data type can be compared with an array. The List can only be used with fundamental types and represents a strongly type list of values that can be accessed by index. So, you can have a List of [Integer], but you cannot have List of [Blob]. A List doesn’t require you to define upfront how many elements you would like to store. A List doesn’t support multi-dimensions as well. This List data type is using the System.Collections.Generic.List<T> Class from the .NET Framework, and this enables you to use some built-in methods.
Before we discuss the methods available on a List, let’s first see how to create a new variable of type List.
List Data Type
The data type List has some methods that are used a lot.

List Functions


When you work with the List data type, there are a number of functions you can apply on that data type. These functions can be used to add items to and remove items from a list, determine the length of the list, find a certain item in the list, etc.
  • ADD(X)
  • CONTAINS(X)
  • GET(index)
  • SET(index, X)
  • INSERT(index, X)
  • Remove(X)
  • RemoveAt(index)
  • Count
  • AddRange(X, [X], [X], …)
  • GetRange(index, count, List of [X])
  • RemoveRange(index, count)
  • IndexOf(X)
  • LastIndexOf(X)
  • Reverse


ADD(X)
The ADD(X) function adds an item X to the end of the list.
CONTAINS(X)
The CONTAINS(X) function checks if an item X exists in the list. It returns a Boolean value, true if found, false if not found.
GET(index)
The GET(index) function gets an item from the list by a certain index and returns that item.
SET(index, X)
The SET(index, X) function updates an item in the list by a certain index. It sets the value X on the item at a certain index.
INSERT(index, X)
The INSERT(index, X) function inserts an item in the list, on a certain index. All the next items are moved one index further.
REMOVE(X)
The REMOVE(X) function removes the first occurrence of an item in the list based on the value of X. This function returns a Boolean value.
REMOVEAT(index)
The REMOVEAT(index) function removes the item on a certain index. This function returns a Boolean value.
COUNT
The COUNT(index) function returns the number of items in a list.
ADDRANGE(X [,X] [,X] [, …])
The ADDRANGE(X) function adds multiple items to the list at the same time.
GETRANGE(index, count)
The GETRANGE(index, count) function retrieves a number of items (count), starting on a certain index. The result is a List of [X].
REMOVERANGE(index, count)
The REMOVERANGE(index, count) function removes a multiple items (count), starting on a certain index. This function returns a Boolean value.
INDEXOF(X)
The INDEXOF(X) function returns the index of the first occurrence of an item based on the value of X.
LASTINDEXOF(X)
The LASTINDEXOF(X) function returns the last index of an item based on the value of X.
REVERSE
The REVERSE function reverses the order of the elements in the list.