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

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 - 

Dynamics 365 Business Central 2021 release wave 2 (BC19) Released.

Hi Readers, As we all were expecting Microsoft have Released Business Central 2021 Release Wave 2 Today a.k.a BC19. In this article we will see what all is announced with the General Availability.  Starting Today Customers & Partners can start using Business Central 19. #msdyn365bc #bc19

Error After Restore SQL Backup of NAV 2013 Database

Hi all, we are facing a conman issue during restoring a SQL Database backup restored for NAV 2013. While Trying to run object from Object Designer we get below listed error (even the service is configured properly) - --------------------------- Microsoft Dynamics NAV Development Environment --------------------------- There are no NAV Server instances available for this database. You must ensure that a NAV Server instance is running and is configured to use the database before you perform this activity. --------------------------- OK    ---------------------------