Tuesday, June 14, 2016

How to: Implement Location in C/AL NAV 2016

How to: Implement Location in C/AL NAV 2016
This example illustrates how you can retrieve location information. The example implements a GetLocation action on the Customer Card (page 21) that returns the GPS coordinates of the current customers address. It does not save this information to the database. Scenarios in which this functionality could be useful would be displaying a map that shows where your customer is located based on the GPS coordinates. Or, functionality to plan the next round of customer visits based on the addresses of your customers.
Important
The location information is only available on devices that run the Microsoft Dynamics NAV Universal App and have GPS capabilities. This means that location information is not available from the Microsoft Dynamics NAV Windows client or from a browser.
To implement location in C/AL
  1. In the development environment, on the Tools menu, choose Object Designer to open the Object Designer window.
  2. In Object Designer, choose Pages, select the Customer Card (page 21) and then choose the Design button.
  3. From the Page Designer window, on the View menu, choose C/AL Globals.
  4. Create the following variable:
Variable name
DataType
SubType
Location
DotNet
Microsoft.Dynamics.Nav.Client.Capabilities.LocationProvider
Important
Choose the Microsoft.Dynamics.Nav.ClientExtensions dll on the Server tab, and then choose Microsoft.Dynamics.Nav.Client.Capabilities.LocationProvider
Make sure to set the properties RunOnClient and WithEvents to Yes.
LocationAvailable
Boolean
  1. On the View menu, select C/AL Code and in the C/AL Editor locate the OnOpenPage trigger.
  2. Instantiate the Location variable by adding the following code to the OnOpenPage trigger.

Copy Code
IF Location.IsAvailable THEN
BEGIN
  Location := Location.Create;
  LocationAvailable := TRUE;
END;
             
           See the bellow screenshot of OnOpenPage Trigger



  1. Next, create the page action. Choose the View menu, and then select Page Actions. 
  1. Locate the ActionGroup named Customer and create a new action; GetLocation with the following properties.
Property
Value
Name
GetLocation
Visible
LocationAvailable
Promoted
Yes
PromotedCategory
Process
PromotedIsBig
Yes

           See the bellow screenshot of GetLocation action Trigger




  1. Now, in the C/AL Editor, on the GetLocation - OnAction trigger, insert the following line of code.
 Copy Code
Location.RequestLocationAsync;

        See the bellow screenshot of GetLocation - OnAction Trigger



  1. While still in the C/AL Editor, on the LocationChanged trigger add the following code to handle the GPS coordinates. LocationChanged is called when the device has obtained a status.

Copy Code
Location::LocationChanged(Location : DotNet "Microsoft.Dynamics.Nav.Client.Capabilities.Location")
IF(Location.Status = 0) THEN
  MESSAGE('Your position: %1 %2',
  Location.Coordinate.Latitude,Location.Coordinate.Longitude)                               
ELSE
  MESSAGE('Position not available');
Important
Location.Status can be 0 = Available, 1 = NoData (no data could be obtained), 2 = TimedOut (location information not obtained in due time), or 3 = NotAvailable (for example user denied app access to location).

           See the bellow screenshot of Location::LocationChanged Trigger


  1. Close the C/AL Editor, and then save and compile the page.
  2. You can now test the modified Customer Card page in the Microsoft Dynamics NAV Universal App from either a tablet or a phone with GPS capabilities.


LocationOptions Overview

Microsoft Dynamics NAV 2016

When implementing location from C/AL, there are some options that you can optionally pass toLocationProvider.RequestLocationAsync(options)
The options can be accessed by usingMicrosoft.Dynamics.Nav.Client.Capabilities.LocationOptions found in the Microsoft.Dynamics.Nav.ClientExtensionsdll.
For most scenarios it is not necessary to specify options.

Location Options List

bool EnableHighAccuracy
A value to provide a hint to the device that this request must have the best possible location accuracy.
int Timeout
The maximum length of time (milliseconds) that is allowed to pass to a location request.
int MaximumAge
The maximum length of time (milliseconds) of a cached location.



References:   MSDN





Wednesday, June 8, 2016

Add a QR Code to a Dynamics NAV 2015/2016 in Report Header

Add a QR Code to a Dynamics NAV 2015/2016 in Report Header
Hi All,
This article will demonstrate how to add a QR Code to a NAV 2016.

For this example I have made a copy of the Order Confirmation Report (ID 205) and save it as QR Order Confirmation (ID 50023).

I have redirected the Company Information Picture field in the report to point to a new BLOB field in the Sales Header Table (ID 36) called “QR Code”.

Note: If you need QR Code Generator Solution Objects, Then ping me, It's free of cost available for learning purpose.
Step 1:  Open Sales Header Table [ID 36] and Add fields [see the bellow screenshot].


After Added fields add some code in OnInsert trigger [see the bellow screenshot].



Step 2:  Create a new codeunit for ”QR Code” functionalities.
                In my case i seted the property Table No with value  ”Sales Header”,
        [ See the bellow screenshot].





In this Codeunit i wrote  four functions for relating QR Code, i.e.
1.       CreateQRCodeInput
2.       GetQRCode
3.       GetBarCodeProvider
4.       MoveToMagicPath

 See the bellow screenshot of full ”QR  Code Management” Codeunit C/AL Code.





Step 3:  Create a Report, In my case i made Save as of Report ID 205 ” Order Confirmation”.
                In that i made some changes:
1.       QRCodeManagement varible of Codeunit of 50010 ” QR Code Management” that earlier created.
2.       Added Data item fields for getting the QR Code Image from Sales Header [See the screenshot].





3.       Add couple of lines in ”Sales Header” OnAfterGetRecord Trigger, to run the ”QR Code Management” Codeunit  and get the QR code image from ”Sales Header” Table [see the bellow screenshot].





Step 4:  Open Report Layout design and create a Image control in Report Header, In my case i used earlier company logo field and populate with new QR fields that i created in Report dataitem [see the bellow screenshot].




After changes save report and exit.

Step 5:  Run the report that you created with require filters [see the bellow screenshot].








Popular Posts