Azure, Azure Function Extension, Azure Functions, DotNet, Http Trigger, node.js, npm, nuget package, QR Code, QRCoder, SDK, Tip & Tricks, Visual Studio Code

Creating Azure Functions to generate QR Code

This is second post in this series, if you wish to see previous post, you can access here.

Today in this post I will discuss about first part, how to create Azure Functions.

Before we start, you need some installation to support creating Azure Functions. Use below Links to download & install these packages on the system, where you wish to write, compile & test the Azure functions.

Installation Links:

https://docs.npmjs.com/downloading-and-installing-node-js-and-npm

https://nodejs.org/en/download/

https://dotnet.microsoft.com/download/dotnet/thank-you/sdk-3.1.414-windows-x64-installer

Obviously, you must have an active Azure subscription, to create an Azure Functions App. If you don’t have, you can create an account that gives you a credit to explore Microsoft Azure for 30 days.

Head to Azure portal and sign in with your account.

Create New Function App.

Select your Azure subscription and a resource group or create a new one. Provide a name for your function app. This name will be the prefix for the URL.

You can select the .NET Core runtime and the region that matches your location. Select the Review + create button.

Now, you can create new functions. A function app can contain multiple functions. Each function will be available on:

Before you start to create Function, you need to Install dependencies:

  1. You should install Visual Studio Code
  2. You should also install Node.JS 
  3. Run the following command to install the Core Tools package:

npm install -g azure-functions-core-tools@3 –unsafe-perm true

Create an Azure Functions project

Click the Create New Project… icon in the Azure: Functions panel.

You will be prompted to choose a directory for your app. Choose an empty directory.

You will then be prompted to select a language for your project. Choose dotnet.

Create a function

If you skipped to provide details, for Functions in above process, you can still initiate later.

Click the Create Function… icon in the Azure: Functions panel.

You will be prompted to choose a template for your function. Select HTTP trigger for getting started.

Screens will be same as shown in above process.

Sample project will be created

As per the information provided by you, in above screens.

KSDQRGenerator.cs auto generated file code will be as below:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace Company.Function
{
    public static class KSDQRGenerator
    {
        [FunctionName("KSDQRGenerator")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            return new OkObjectResult(responseMessage);
        }
    }
}

Now you have the Http Template, we will make necessary changes as per our requirement.

In this example we will be using a library – QRCoder to generate the QR Code.

So first we have created a function with Http Trigger.

Made changes to the function as:

/*string name = req.Query["name"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            return new OkObjectResult(responseMessage);*/

Replace this part as below code:

            string ReqData = req.Query["ReqData"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            ReqData = ReqData ?? data?.url;
            if (string.IsNullOrEmpty(ReqData))
            {
                return new BadRequestResult();
            }

            var generator = ReqData;
            var payload = generator.ToString();

            using (var qrGenerator = new QRCodeGenerator())
            {
                var qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q);
                var qrCode = new PngByteQRCode(qrCodeData);
                var qrCodeAsPng = qrCode.GetGraphic(20);
                return new FileContentResult(qrCodeAsPng, "image/png");
            }

Final Code should look like this:

There are some errors, correct. Next step will resolve the same.

Next, we will add the QRCode nuget package to the dotnet core project using 

dotnet add package QRCoder –version 1.4.1

Post completing the command execution, all errors are resolved.

Run your function project locally

Press F5 to run your function app.

The runtime will output a URL for any HTTP functions, which can be copied and run in your browser’s address bar.

Copy the URL of the function & Switch to browser:

In my case: http://localhost:7071/api/KSDQRGenerator?ReqData=Test

If you scan above QRCode, you will get ‘Test’ as we have passed this as a parameter (?ReqData=Test)

To stop debugging, press Shift + F5.

Deploy your code to Azure

Click the Deploy to Function App… () icon in the Azure: Functions panel.

Sign in to your Azure Account, if not done earlier. To test locally you need not to sign in to Azure. But at deployment is must.

When prompted to select a function app, choose KSDQRCodeGenerator (in my case), Function App Created on Azure portal in the starting of this blog post.

Confirm to deployment dialog.

On completion you will get the Live AZURE URL, use the URL in same way as for local, to pass parameter append at the end of URL as (?ReqData=Test)

Replace [Test] with the information for which you want to generate the QR Code.

That’s all for this post, but visit again to learn from upcoming posts in this series, will post soon.

See you again in next post, Till then keep exploring, learning and sharing with others.

Advertisement
Dynamics 365, How To, Information, Modern Development Tool, NAV 2018, Tip & Tricks, Updates, What's New

NAV Development Preview – Modern Development Tools for Dynamics NAV

Dear friends, after writing blog on Modern Development Tools for Dynamics NAV few of my readers requested to compile all information related to this in single blog.

Here are the links related to these posts, not all are my but are useful and will help keep you updated on same.

Extensions 2.0

Configuring Visual Studio Code

Below are the helpful other links from Microsoft Dynamics NAV Team

How do I learn more?

Check out these docs:

Tools overview

Getting Started guide

Object overview and AL language changes

Modern Development Tools Updates

released from launch till Dec 2017

Modern Development Tools for Dynamics NAV

NAV Development Tools Preview – January Update

NAV Development Tools Preview – February Update

NAV Development Tools Preview – March Update

NAV Development Tools Preview – April Update

NAV Development Tools Preview – June Update

NAV Development Tools Preview – July Update

NAV Development Tools Preview – August Update

NAV Development Tools Preview – September Update

NAV Development Tools Preview – October Update

NAV Development Tools Preview – November Update

NAV Development Tools Preview – December Update

Hope you find this information useful in understanding and learning the new Modern Development Tool for Dynamics NAV 2018.

 

 

 

 

 

 

 

Development Tips, Dynamics 365, Extension Package, How To, Information, NAV 2018, Tip & Tricks, What's New

Extensions 2.0 – Dynamics Navision 2018

The issue with customizations is that they often introduce challenges when upgrading. It’s hard to upgrade a solution from one version to the next when changes have been made to the underlying solution. Extensions, and the new version – Extensions 2.0 – solves this problem.

Instead of defining customizations in the original source code, extensions are written alongside the solution source, where the integration with the source is handled with events. An extension can add new objects and extend existing objects that are present in the solution. The extension code is packaged in a file, which you can deploy to your solution. This allows us to upgrade the underlying solution and, as long as the events remain, the extension will behave in the same way from version to version.

To help you developing solutions for this new programming pattern, you can use the new developer tools to build, test, and deploy extensions.

 

In app designer

In the client, you can switch to the in app designer mode that provides a way for you change the look and feel of the client easily and quickly. In short, the in-client designer lets you define what elements (such as fields, groups) appear on a page and how they are arranged. The in-client designer also provides an interactive way to create extensions based on changes you make in the client. Some of the features include:

  • Adding a field from the source table to a page.
  • Moving a field to another place on a page.
  • Removing a field from a page.
  • Previewing your design in desktop, tablet, and phone clients.
  • Saving the changes for the tenant or saving as an extension package file in Visual Studio Code.
  • Changing the caption of a fields on the page.
  • Adding, moving, renaming, and removing an action.
  • Adding, moving, and removing page parts.
  • Adding new pages.

 

Personal and organizational design changes

As an end user, changes can be applied so that only the user who made the changes will see them. This enables users to personalize the pages for their role. Examples of personalization could include moving important fields to a more prominent position on the page, or renaming a date field so that it is clearer which field is the ship date versus the expected arrival date. Alternatively, as an administrator, changes can be made globally, so that everyone in the organization can see them.

Business consultants can also access the same tools to help customers make changes to their solution, resulting in improvements in productivity for all users. For example, they could add new actions to run custom reports, or introduce entirely new pages or page parts.

 

Working with the In App Designer

To turn on the In-App Designer, start the client as normal, and then simply choose the In-App designer icon in the ribbon on any page in the client.

 

ExtV2-1

The Design mode bar appears at the top page, indicating that the in-client designer is active. You can now open any page, and start making changes.

ExtV2-2

Choose More to display additional design options, such as adding a field, creating a new field, and changing the preview to another client type.

ExtV2-3

 

ExtV2-4

To move a field, click and hold the handle in the field to drag and drop it from its current position to the new location, as indicated by the horizontal line.

ExtV2-5

To remove a field, click the field’s handle, and then choose Remove.

ExtV2-6

To add a field, choose the Field button, and then drag and drop a field from the list that appears to the desired location.

ExtV2-7

To preview in another client type, simply choose one of the preview buttons.

When you are finished making changes, choose Stop Designing. You then have the option to save the changes to the tenant for all users, or to save the changes to a file that you can work on later in Visual Studio Code.

ExtV2-8

You can see that Extension is deployed on your solution, check as below.

ExtV2-9

Hope you will enjoy using this new feature of development.

Will come with more details as I proceed.

Development Tips, Dynamics 365, Extension Package, How To, Information, Instalation & Configuration, NAV 2018, Tip & Tricks, Visual Studio Code, What's New

Configuring Visual Studio Code to Use Modern Development Environment with Dynamics NAV 2018

After installing Dynamics NAV 2018, I want to configure Visual Studio Code with Dynamics NAV to use new Development tool.

Before we start lets verify few things and update accordingly.

NDE-1

You can download VS Code from here:-Click to download Visual Studio Code

Install and Launch the Visual Studio Code.

Now Click View -> Extensions.

NDE-2

Click on … to open the extension menu.

Click on Install from VSIX

NDE-3

You can find VSIX file on the installation medium path:

“ModernDev\program files\Microsoft Dynamics NAV\110\Modern Development Environment”

or in the

“C:\Program Files (x86)\Microsoft Dynamics NAV\110\Modern Development Environment”

NDE-4

This will install AL Language Version 0.12.15355

NDE-5

Once the Extension installation is complete, follow below steps

Press Alt+A, Alt+L to trigger the Go! Command

NDE-6

Enter Project Name and Press Enter

NDE-7

Choose “Your own server”

Once you select the “Your own server” you will see a code like below in the “launch.json” file.

NDE-8

Update the information to look similar to below:-

NDE-9

I have updated my ServerInstance as DynamicsNAV110 (you check your instance name if changed while installing server)

I have updated my Authentication as Windows (I am using Windows authentication update what yours use accordingly)

I have added Port as 8049 (please check and use accordingly you are using the port, if using default 7049 then this step not required)

Now save your File. And Press <CTRL + F5>.

NDE-12

Enter your Credentials.

The server url and the web client url are assumed to be the same. That is not the case. The two settings we talked about above, the server url and the developer port number, are the only settings you need in the launch.json.

When VS Code publishes the extension to the NAV server, the NAV server returns the web client url as a response. This url is then opened in the browser. No setting needed in the launch.json at all.

The NAV server reads that setting from the Web Client Base Url server setting.

NDE-13

NDE-11

Your Extension is published, you can verify as below:

NDE-10

Now you are good to go with developing your Extensions using New Modern Development Tool using AL.

I hope this may have clarified your doubt on how VS Code and the NAV server work together!

I will come with more details as I proceed.