web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Replacing DOTNET.

Jalmaraz Profile Picture Jalmaraz 669

Introduction.

In one of the last Nav extension updates, Microsoft Team has announced that DOTNET are enable in extensions onPrem installations.
A lot of people don´t like DOTNET due security issues. I will not talk about security, because I don´t know very much about this subject.
I don´t like DOTNET because when we use DOTNET, we don´t do what really NAV does very well: business logic.
With DOTNET, we do other related things, but not business logic. It´s about productivity, is about not reinventing the wheel and spend a lot of time and support efforts in unknown territories. Using DOTNET from NAV most of times involves knowing a lot about that DOTNET component internal behavior.

Substitution strategies.

We can consider two approaches:
  • Microservices. External small programs (Visual Studio), that do the work and call a NAV web service or leave the result in a file. We can use third party components or develop them in Visual Studio.
  • Http APIS. There is a world plenty of APIs to do that work for us. Some time ago, Http calls were complex, but now with HTTP Client are very easy.
Good Http APIs are pay-per-use, but we must assume this fact in cloud world.

Example. Making QR codes with APIs.

When we look solutions to encode QR from NAV, always are focused to dll or DOTNET components. This force us to make a lot of code and know too much about how QR codes work.
Let´s do a demo with external API call.

Step 1.

Open in VS Code a new AL project and create a new page with two variables:
var
    Url: Text;
    Filename: Text;

Step 2.

We get them in two text boxes:
            {
                field("Url to visit";Url)
                {
                    ApplicationArea = All;
                    CaptionML = ENU = 'Url to visit';
                }
                field("File to save result";Filename)
                {
                    ApplicationArea = All;
                    CaptionML = ENU = 'File save result';
                }
 

Step 3.

A new function that call Url with HttpClient and save the response in a file:
local procedure VisitUrlAndSaveFileResult(Filename: Text)
    var         
        ClienteHttp: HttpClient;    
        Llamada: HttpRequestMessage;
        Respuesta: HttpResponseMessage;
        FlujoEntrada: InStream;
    begin
        Llamada.SetRequestUri(Url);
        if not ClienteHttp.send(Llamada,Respuesta) then
            Error('Call failed');
        Respuesta.Content.ReadAs(FlujoEntrada);
        DownloadFromStream(FlujoEntrada,'Descarga','','',Filename);
    end;            
}

Step 4.

An action button to call this function:
            action(ActionName2)
            {
                    Caption='Visit Url and save file result';
                    ApplicationArea = All;
                trigger OnAction()
                begin
                    VisitUrlAndSaveFileResult(Filename);
                end;
            }

Execute the page and generate QR image.

I publish the extension and run it in 365 Business Central (SAAS). Then we open the page:
 DOTNET1.png
I fill in Url to visit https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=TIPSA.VINOTEC. It´s an API that takes in URL the parameters. I set the QR content in data=TIPSA.VINOTEC. It´s the free use version, so they add some extra character at the beginning to avoid the use without paying, but it´s OK to show its capabilities.
When I push Visit Url and save file result, the API returns a .png file with QR:

DOTNET2.png

If I push open ("Abrir") we can see the consequent OCR image saved in a file:

DOTNET3.png

I think this way is easier than using DOTNET components.

C/AL version.

I did the C/AL version too, if someone is interested I can write another related post.

Comments

*This post is locked for comments