Monday, 29 May 2017

Web Page Viewer Control Add–in - Part 01 - Report Viewer

Web Page Viewer control add-in was introduced in NAV 2017.



Below are the lists of page objects where the Web Page Viewer control add-in is used.




In this post, we will first see how this add-in works in the Page 2115 Report Viewer.
We need to set the user personalization to use the O365 SALES profile, as the below listed page objects are using the report viewer.



Highlighted are the new Role Centers that is available in NAV 2017.

Set the O365 SALES profile id for your user id and reopen the client.
Windows Client:
Login in to NAV.


Select and open one of the Posted Sales Invoices from the Invoices part.

Click on the View Invoice and the Invoice will be displayed in the Report Viewer.

So from where these details are displayed?
These details are displayed from the Report 1306 - Standard Sales – Invoice, based on the setup in the Report Selection Sales. The report is first saved to a HTML file and then the HTML file content is displayed in the Report Viewer through Web Page Viewer control add-in.
The same works on the Web Client.







Below is the code snippet, you can check more details from the development environment.
Page - 2113 - O365 Posted Sales Invoice, View Invoice (ViewPdf) action:

Page -2115 - Report Viewer - Function

We will see other pages that are using the Web Page Viewer Control Add-in in the next post.

Thursday, 18 May 2017

How to calculate the current UTC Time Zone from Navision?

There was a case where i need to get this kind of output hh:mm:ssZ where Z stands for UTC Time Zone (20:15:00+0200) to the external system for integration.
For Instance, the current time zone in the system is UTC +02:00 and we need to get this value (+0200) from Navision. There are no predefined functions to get this value so for that i have created a new function GetUTCOffset which can be used to get the UTC offset.
LOCAL PROCEDURE GetUTCOffset@5() : Text;
VAR
lLocalTime@1004 : Time;
lUTCTime@1000 : Time;
lDateTimeTxt@1003 : Text;
lTimeTxt@1001 : Text;
lTimeDiffTxt@1002 : Text;
lSign@1005 : Text;
BEGIN
//GetUTCOffset
EVALUATE(lLocalTime,'17:00');
lDateTimeTxt := FORMAT(CREATEDATETIME(TODAY,lLocalTime),0,9);
lTimeTxt := COPYSTR(lDateTimeTxt,STRPOS(lDateTimeTxt,'T') + 1);
lTimeTxt := COPYSTR(lTimeTxt,1,STRLEN(lTimeTxt) - 1);
EVALUATE(lUTCTime,lTimeTxt);
lTimeDiffTxt := FORMAT((lLocalTime - lUTCTime) / 3600);
lSign := '+';
IF lTimeDiffTxt[1] = '-' THEN BEGIN
lSign := '-';
lTimeDiffTxt := DELCHR(lTimeDiffTxt,'=','-');
END;
EVALUATE(lLocalTime,lTimeDiffTxt);
EXIT(FORMAT(lLocalTime,0,lSign + '<hours24,2><minutes,2>'));
END;
Output:
If the Time zone is UTC +02:00 then the Output will be +0200
If the Time zone is UTC +02:00 and we have DST (Daylight Saving Time) then the Output will be +0300
Note:
I have formatted the final output of the Time to remove the “:” using the below code.
FORMAT(lLocalTime,0,lSign + '<Hours24,2><Minutes,2>')
You can format the output per your requirement.
Please do let me know if in case there are some issues & suggestion about the code & approach. Thanks

Evaluating text value to decimal value based on the regional settings.

This is my first blog and i wish to take this as a platform to share my experience with MSD NAV. In this first post, i am sharing some basics about formatting the decimal text value before evaluating it to the decimal data type based on the regional settings. Hope this article is useful.

There are scenarios where we need to import / process a decimal text value to decimal field and it should work with different regional settings.

For example:
Decimal Text Value is 10.50 and the Regional Settings is using Comma as a decimal separator. In this case we need to convert the decimal separator in the text value to that one that is used in the regional settings before evaluating the decimal text value to decimal data type.

Below is the code for Converting the Decimal Text Value to Decimal Data Type:

OnRun()
MESSAGE('From Point Decimal Separator to Regional Settings (. --> ,) %1',ConvertTextToDecimal('10.50'));

MESSAGE('From Comma Decimal Separator to the Regional Settings (, --> ,) %1',ConvertTextToDecimal('10,50'));

    PROCEDURE ConvertTextToDecimal@1000000020(pDecText@1000000000 : Text) : Decimal;
    VAR
      lDecimal@1000000001 : Decimal;
    BEGIN
      //ConvertTextToDecimal
      IF pDecText = '' THEN
        EXIT(0);
      EVALUATE(lDecimal,FormatDecimal(pDecText));
      EXIT(lDecimal);
    END;

    PROCEDURE FormatDecimal@1000000009(pDecText@1000000000 : Text) : Text;
    VAR
      lDefaultDecimalSeparator@1000000001 : Text[2];
    BEGIN
      //FormatDecimal
      lDefaultDecimalSeparator := COPYSTR(FORMAT(1 / 2),2,1);
      CASE lDefaultDecimalSeparator OF
        '.': EXIT(CONVERTSTR(pDecText,',','.'));
        ',': EXIT(CONVERTSTR(pDecText,'.',','));
        ELSE
          EXIT(pDecText);
      END;
    END; 

Regional Settings:
  


Output after running the code unit:


Please do let me know your suggestion. Thanks