Skip to main content

NAVISION - How To Display Time in Words.

Hi all,

This is nothing most of you would be interested in. This post only show steps about how to Display Time in words in Navision.

If you don't know this, then please go ahead.

The intended readers for this post are the Peoples who have recently joined and are still Learning NAV. Based on a Query from a Friend Via Contact Form.


This post list down the steps and objects that i have used to complete the requirement. I have done it for NAV 2009 Classic Client and As well as on NAV 2013.

Let's Start and see how we can achieve it.

Concept -
---------------------------
1. First thing that came to my mind that Navision Report 1401 Check contain a function which is able to convert Amount in Words. - I will be Referring That.

2. Second Thing that comes to my mind is date actually contain Decimal values separated with a date separator commonly ':'.
---------------------------

What i need to Do?
---------------------------
1. Separate the Date in three parts - Hours, Minutes & Seconds.

2. Create a copy of Standard Function in Report 1401 - FormatNoText, to convert Date in Words.

OR

2. Copying Related Function From Report 1401 Check to My Form & Page.

In Demo i will be Copying Function to My Form & Page but i would suggest to make a copy of the function in 1401 instead of make the form or page clumsy.
---------------------------

**I am not doing it in Report itself as the Report 1401 contain localization which may be be different in your case.

Step 1 - (Breaking Dates in Parts) -

- Created a Form / Page with a input field which will accept Time.

- Create a Button / Action, on click on which the date will be Break into Three parts.

- On Push Action
   1. Check the Input Value.
   2. Convert Time in Text.
   3. Break Time in Hours Minutes and Seconds.
   4. Convert Time from 12 Hours to 24 Hours.

CODE
----------------------------------------------------
IF InputTime = 0T THEN
  ERROR('Input Time Value');

TimeInText := FORMAT(InputTime);                  

EVALUATE(TimeParts[1],COPYSTR(TimeInText,1,2));      
EVALUATE(TimeParts[2],COPYSTR(TimeInText,4,2));      
EVALUATE(TimeParts[3],COPYSTR(TimeInText,7,2));      

IF COPYSTR(TimeInText,10,2) = 'PM' THEN
  TimeParts[1] += 12;
----------------------------------------------------
Where -
InputTime - Time.
TimeInText - Text (12).
TimeParts - Decimal (Array Dimension 3).

Step 2 - Copying the Related Function, Variables & Text Constants from 1401 to my form/Page.

I will copy following functions -

1. FormatNoText (Renamed the Function to - FormatNoTime)
2. AddToNoText
3. InitTextVariable

Copying Following Global Variables -
OnesText
TensText
ExponentText

Copying Text Constants -

1. Text026 TO Text028
2. Text032 TO Text058

Below are the Changes that i have done in the Standard Function Copied From Report 1401- 

**Only Changed Code Shown in Below Images

Function FormatNoText (Standard) VS FormatNoTime (Customized)

Removed Code in Customized Function where Currency Related Constants are added like Rupee for INR.

Other than Highlighted Part other Code Remain Same.


Function InitTextVariable -

Removed Code in Customized Function. Other than Highlighted Part other Code Remain Same.


4. Now i will append code in Push action of same button as shown below -

CODE
----------------------------------------------------
CLEAR(TimeinWords);
InitTextVariable();                    
FormatNoTime(Output,TimeParts[1],'');  
TimeinWords += Output[1] + ' HOURS ';
FormatNoTime(Output,TimeParts[2],'');
TimeinWords += Output[1] + ' MINUTES ';
FormatNoTime(Output,TimeParts[3],'');
TimeinWords += Output[1] + ' SECONDS ';
MESSAGE(TimeinWords);
----------------------------------------------------
Where - 
TimeinWords - Text (90)
Output - Text (80) - (Array Dimension 2).

What this code does?

 > Clear the Text Variable.
 > Initialize the Text Variables.
 > Do the Conversion for Each Part and Append that to a Text Variable.

Let's Try Executing the Form & Page. Below the screens running the Form & Page in 2009 & 2013.

Input Window -


Output Window -



Objects can be Downloaded in Text & FOB From My Skydrive.
File Name - Convert Time in Words.zip

I hope you find the post useful and let me know the feedback of such basic Navision post on the Contact form or as a comment to post.

Stay Tuned for More.

Regards,
Saurav Dhyani
www.sauravdhyani.com

Comments

  1. Sir, As I want to convert Numbers to Text. for ex, if i give 1 output should be One and so on. can i have code for that...

    ReplyDelete

Post a Comment

Popular posts from this blog

BC 21 and Higher - PowerShell Cmdlet (Replacement of Business Central Administration).

Hi Readers, As discussed in last article about deprecating of Business Central Administration, there are few common actions that we use in administration till Business Central 20. For our on-prem customers, we will still require doing activities. As Microsoft suggest we need to start using PowerShell cmdlet.    Let's see how to do those via PowerShell, or Administration Shell. I will be keep adding commands as you comment to this article.

Send Mail with Attachment From Navision.

Hi all, We have seen how to save a report into PDF and how to send mail to a customer. Let's link these two post in one i.e. Mailing statement to a customer into PDF Format. This article is part of the Series. Please Refer  Table of Content here . If you have the old objects set let me brief you what I will be changing - 

MSDYN365BC - Data Upgrade To Microsoft Dynamics 365 Business Central on premises.

Hi Readers, We have already talked about the number of steps for upgrading to Business Central on Premises from different NAV versions. After that article, I received multiple requests for an article which list down steps for Data Migration. In this article, we will discuss steps of data migration to MSDYN365BC (on-Prem) from NAV 2017. For this article, I am considering a Cronus Demo Database without any customization. For an actual upgrade project, we will have to complete object merge using compare and Merge process. After the Merge Process, the next step is data migration. Let's discuss those steps. Direct Upgrade to Microsoft Dynamics 365 Business Central (on-Prem) is from following versions - 1. NAV 2015. 2. NAV 2016. 3. NAV 2017. 4. NAV 2018.