Book Image

Microsoft Dynamics NAV 7 Programming Cookbook - Second Edition

Book Image

Microsoft Dynamics NAV 7 Programming Cookbook - Second Edition

Overview of this book

Microsoft Dynamics NAV 7 is a business management solution that helps simplify and streamline highly specialized business processes. Learning NAV programing in NAV 7 gives you the full inside view of an ERP system. Microsoft Dynamics NAV 7 Programming Cookbook covers topics that span a wide range of areas such as integrating the NAV system with other software applications including Microsoft Office, and creating reports to present information from multiple areas of the system,. We will not only learn the essentials of NAV programming, you will also be exposed to the technologies that surround NAV including.NET programming, SQL Server and NAV system administration. Microsoft Dynamics NAV 7 Programming Cookbook is written in a direct, to-the-point style to help you get what you need and continue working in NAV. The first half of the cookbook will help programmers using NAV for the first time, by walking them through the building blocks of writing code and creating objects such as tables, pages, and reports. The second half focuses on using the technologies surrounding NAV to build better solutions. You will learn how to write .NET code that works with the NAV system and how to integrate the system with other software applications such as Microsoft Office or even custom programs. You will learn everything you need to know for developing all types of NAV CSIDE objects, as well as how to integrate and maintain a NAV system.
Table of Contents (20 chapters)
Microsoft Dynamics NAV 7 Programming Cookbook
Credits
About the Author
About the Reviewers
Acknowledgements
www.PacktPub.com
Preface
Index

Retrieving the work date


To perform tasks such as completing transactions for a date that is not the current date, you may have to temporarily change the work date. This recipe will show you how to determine what that actual work date is as well as when and where you should use it.

Getting ready

  1. Navigate to Application Menu | Set Work Date or select the date in the status bar at the bottom of Microsoft Dynamics NAV.

  2. Input the work date in the Work Date field or select it from the calendar.

How to do it...

  1. Let's get started by creating a new codeunit from Object Designer.

  2. Then add the following code into the OnRun trigger of the codeunit:

    MESSAGE('Work Date: %1\Todays Date: %2\Current Time: %3',WORKDATE, TODAY, TIME);
  3. To complete the task, save and close the codeunit.

  4. On executing the codeunit, you should see a window similar to the following screenshot:

How it works...

To understand WORKDATE, we have used two more keywords in this recipe. The work date is a date internal to the NAV system. This date is returned using the WORKDATE keyword. It can be changed at any time by the user. The next date is TODAY; it's a keyword to retrieve the present date that provides the date from the system. In the end, we used the TIME keyword, which provides current time information from the system clock.

Note

It is important to understand the difference between the NAV work date and the computer system date; they should be used in specific circumstances. When performing general work in the system, you should almost always use the WORKDATE keyword. In cases where you need to log information and the exact date or time when an action occurred, you should use TODAY or TIME, or CURRENTDATETIME.

There's more...

The following code can be found in the 38, Purchase Header table, in the UpdateCurrencyFactor() method:

IF "Posting Date" <> 0D THEN
CurrencyDate := "Posting Date"
ELSE
CurrencyDate := WORKDATE;

Looking at this code snippet, we can see that if a user has not provided any specific posting date, the system will assign the value WORKDATE as the default value for the posting date.

See also

  • Determining the day, month, and year from a given date

  • Converting a value to a formatted string

  • The Checking for conditions using an IF statement recipe in Chapter 2, General Development

  • The Using the CASE statement to test multiple conditions recipe in Chapter 2, General Development