Tag: NAV

How to: Access timestamp from C/AL

How to access timestamp from C/AL? When you Google/Bing this question, you mainly get three answers:

  1. Short answer: you can’t,
  2. Write a SQL query using ADO.NET,
  3. Create a SQL view and use a linked table on NAV,

When Microsoft introduced NAV 2016, we got a fourth answer described in this blog post by Dynamics NAV Team Blog.

Here is my point of view about these solutions:

  1. Solutions 1: is not a solution,
  2. Solution 2: is like you use a hammer to kill a mosquito,
  3. Solution 3: well, this is not a solution too because:
    • You have to create a view on your database and this will give some headache when you upgrade…
    • You have to consume a table: what if you want to have the timestamp for records from two/three/N tables ? Would you create N dummy views and N linked tables? If it was me, the answer is a big NO.
  4. Solution 4: these is a great and useful improvement but:
    • You may have to customize standard tables (add new field of type BigInteger and set property “SQL Timestamp” to Yes)… Yet another customized table you may need to handle during your upgrades 🙁
    • What about older versions?

After this short introduction (short?), I get right to the point “here is a fifth solution in three lines of code“:

IF NOT DataTypeManagement.GetRecordRef(_RelatedRecord, RecRef) THEN
EXIT(0);

EVALUATE(timestamp, FORMAT(RecRef.FIELD(0).VALUE));

Want to try it? Here is the fob for Dynamics NAV 2013. In this fob, the function GetTimestamp returns the decimal value for the record’s timestamp.

This solution works for Dynamics NAV 2013 and later. Unfortunately, it does not work for Dynamics NAV 2009 R2 or older.

This blog is available also on Microsoft Dynamics NAV Community

Print to different trays in NAV – Part 4

This post is part of a series of posts where I explain how to print to different trays in NAV.

  1. Print to different trays in NAV – Part 1
  2. Print to different trays in NAV – Part 2
  3. Print to different trays in NAV – Part 3
  4. Print to different trays in NAV – Part 4

In this forth and last part, we’ll simply print a sales invoice respecting the following requirements:

  1. The first page should print from first tray where we will use a colored paper,
  2. The last page should print from second tray where we will use preprinted paper where we can read general terms and conditions in the back,
  3. Other pages should print from the lower tray for example.

To fulfill this requirement, we’ll use the options already described in Part 1.

For test purpose, I will save report “Sales – Invoice” (ID 206) under a new name and number. I’ll adjust properties as below:

  • PaperSourceFirstPage  = Custom 2,
  • PaperSourceDefaultPage = Lower,
  • PaperSourceLastPage = Custom 3.

Then I’ll create an invoice, post, and print it. Voilà !

Sources and examples are available here.

That’s great. But when you print multiple invoices or when you print multiple copies of your invoice, you’ll quickly notice that NAV does not pages in the right trays.

Unfortunately, this is a limitation in Windows Client / RTC because:

  • RDLC does not support PAPERSOURCE,
  • RDLC uses report properties for physical pages only.

Of course, this limitation is not relevant for NAV 2009 R2 Classic Client and older versions because you can force PAPERSOURCE in the code.

But hey, you should upgrade your NAV if you still use NAV 2009 R2 or older. So, you’ll face these limitations soon 😀

This was the last part of this blog post series. I hope it will help someone. Please share your ideas or just say hello if you like my work.


This blog is available also on Microsoft Dynamics NAV Community

Print to different trays in NAV – Part 3

This post is part of a series of posts where I explain how to print to different trays in NAV.

  1. Print to different trays in NAV – Part 1
  2. Print to different trays in NAV – Part 2
  3. Print to different trays in NAV – Part 3
  4. Print to different trays in NAV – Part 4

In this third part, we’ll see how you can find what are available trays in your printer.

To do this, I will explain two solutions.

Solution 1:

This solution is based on a simple tool called “FindTrays”. This tool was kindly shared by Timo Lässer from German NAV community msdynamics.de. You can directly download FindTrays from this link.

You can get available trays by executing this command line:

.\FindTrays.exe “MyPrinterName” > .\AvailableTrays.txt

How do you get your printer’s name? Simple, just go to your printer properties and you’ll find it under the general tab.

Solution 2:

The second solution I suggest is based on NAV. The idea is to create a simple report that prints the tray number using:

  • PAPERSOURCE function for NAV 2009 R2 Classic Client and older version,
  • Properties PaperSourceFirstPage, PaperSourceDefaultPage and PaperSourceLastPage for version with Windows Client / RTC (i.e. NAV 2013 and later).

Sources and examples are available for download here. Enjoy!

In the fourth part, we’ll apply what we learned, and we’ll discuss some NAV limitations.


This blog is available also on Microsoft Dynamics NAV Community

Print to different trays in NAV – Part 2

This post is part of a series of posts where I explain how to print to different trays in NAV.

  1. Print to different trays in NAV – Part 1
  2. Print to different trays in NAV – Part 2
  3. Print to different trays in NAV – Part 3
  4. Print to different trays in NAV – Part 4

In this second part, we’ll see how you can test your printing in different trays.

If you need to test your printing you will, of course, need a printer that support printing in different trays. But what if you don’t have such a printer? Or, what if you -like me- hate to waste paper on your tests?

The answer is Bullzip PDF printer. In fact, this proprietary PDF virtual printer allows to add virtual trays. I’ll let you read complete explanation in Bullzip Knowledge Base.

Just in case the link is down, I’ll quickly explain the steps hereafter. All you need to do is:

  1. Download and install the virtual printer with default parameters (adjust if needed),
  2. Open, as admin, the “BULLZIP.PPD” file located in “C:\Windows\System32\spool\drivers\x64\3\“,
  3. Add the lines below to the end of the file and save it:

*InputSlot Tray1/Tray 1: “gsave /Times-Roman findfont 30 scalefont setfont newpath 10 10 moveto 1 0 0 setrgbcolor (Tray 1) show grestore”
*InputSlot Tray2/Tray 2: “gsave /Times-Roman findfont 30 scalefont setfont newpath 10 10 moveto 1 0 0 setrgbcolor (Tray 2) show grestore”
*InputSlot Tray3/Tray 3: “gsave /Times-Roman findfont 30 scalefont setfont newpath 10 10 moveto 1 0 0 setrgbcolor (Tray 3) show grestore”
*InputSlot Tray4/Tray 4: “gsave /Times-Roman findfont 30 scalefont setfont newpath 10 10 moveto 1 0 0 setrgbcolor (Tray 4) show grestore”
*InputSlot Tray5/Tray 5: “gsave /Times-Roman findfont 30 scalefont setfont newpath 10 10 moveto 1 0 0 setrgbcolor (Tray 5) show grestore”

You can download the file I created here (delete .doc from the extension).

Now that the printer is ready, let’s see how you can find out what are the available trays in your printer. The answer is in part 3.

P.S 1: this blog is primarily addressed for NAV developers.

P.S 2: this blog could be of use for none-NAV developers also as it explains a solution to create virtual printer with different trays.

P.S 3: The same trick works also for PDFCreator (i.e. add virtual trays to the virtual printer). So, you can try it with your preferred virtual printer. The PPD file is available in the same location “C:\Windows\System32\spool\drivers\x64\3\PDFCREAT.PPD”.


This blog is available also on Microsoft Dynamics NAV Community

Print to different trays in NAV – Part 1

This post is part of a series of posts where I explain how to print to different trays in NAV.

  1. Print to different trays in NAV – Part 1
  2. Print to different trays in NAV – Part 2
  3. Print to different trays in NAV – Part 3
  4. Print to different trays in NAV – Part 4

In this first part, we’ll quickly talk about options available in NAV that allow printing to different trays.

First, let’s check properties of report “Sales – Invoice” (ID 206):

ReportProperties.jpg

As you can see there are three properties that will allow you select the tray where the page should print. Below, you can read help from MSDN:

  1. PaperSourceFirstPage Property
  2. PaperSourceDefaultPage Property
  3. PaperSourceLastPage Property

Available values for each property are described here: Paper Sources and Tray Numbers This link refers to “Norway Local Functionality”, though it explains all available trays numbers in any NAV database (W1 and Localizations).

P.S: In NAV 2009 R2 and older versions, the available options are PaperSourceFirstPage and PaperSourceOtherPages.

In the next blog, I will explain how you can try those options without having a printer with different trays.


This blog is available also on Microsoft Dynamics NAV Community

Text encoding in NAV 2009 R2 Classic Client – Part 2

As I already explained in this blog post you can import text files with encoding in Dynamics NAV 2009 R2 Classic Client and old versions.

Today, I will use the same trick to export a text file with encoding (UTF-8 in the example below).

To illustrate this, let’s export all items in a text file from a Russian database. I’ll use three possible solutions:

1- Via dataport:

Dataport-Export Item.jpg

2- Via codeunit using variable of type File:

Codeunit File-Export Item.jpg

3- Via codeunit using variable of type Automation (Stream):

Codeunit Stream-Export Item.jpg

Now, let’s see the results:

Result.jpg

We quickly notice that export via dataport or via File variable does not do the job as Russian characters are not exported correctly whereas export via Stream does the job perfectly.

As always, I let you download the objects and files I used in this blog post.

This blog is available also on Microsoft Dynamics NAV Community

How to: Set Up Multiple Web Server Instances for the Microsoft Dynamics NAV Web Client – Part 1

No, you guessed wrong! I am not going to add another blog to explain how to use Powershell to create and setup a Dynamics NAV Web Instance.

As a quick reminder you can refer to msdn here and use Microsoft Dynamics NAV Administration Shell to easily create a new web instance.

But what if I cannot use Microsoft Dynamics NAV Administration Shell? Yes, now you guessed right. This is the reason behind this blog post.

Scenario (summary in three points):

  • You installed NAV Server and Web Server on separate machines.
  • In your NAV Server you can locate Microsoft Dynamics NAV Administration Shell.
  • In your Web Server you cannot locate Microsoft Dynamics NAV Administration Shell.

You quickly notice that you cannot apply what msdn says, because simply you do not have Microsoft Dynamics NAV Administration Shell installed on your Web Server.

What is the solution then? From my side, I explored two options:

  1. Powershell remote session from NAV Server to Web Server and apply the New-NAVWebServerInstance,
  2. Build a Web Instance from scratch.

I quickly dropped the first option due to network and firewall issues and because the second option sounds more fun 😉

So, let’s build that web instance.

To achieve that, open your IIS and locate the default Web Instance, “DynamicsNAV90” in my case.

iis_web_client

It is easy now. You just must create the same structure (I highlighted the important parts).

  • Create a virtual directory,
  • Give it a name: MyWebClient
  • Point the physical path to a folder: “C:\inetpub\wwwroot\MyWebClient”
virtual_directory

Now, execute this command line as administrator:

mklink /d “C:\Inetpub\wwwroot\MyWebClient\WebClient” “C:\Program Files\Microsoft Dynamics NAV\90\Web Client”

This will create a symbolic link to the “C:\Inetpub\wwwroot\MyWebClient\WebClient” that points to “C:\Program Files\Microsoft Dynamics NAV\90\Web Client”.

Then, copy the “web.config” from the default web instance and past it to MyWebClient (Change the web.config to point to another NAV Server if needed):

webconfig

Now, create the following folder “C:\ProgramData\Microsoft\Microsoft Dynamics NAV\90\Web Client\MyWebClient\WebClient\Resources\ExtractedResources” and assign the following permissions to IIS_IUSRS:

ExtractedResorces

Create a Virtual Directory that points to the folder we just created:

ExtractedResorces_virtualdirectory

Last step, convert “WebClient” to an application:

application

Now, try to connect to your new and freshly created web site http://localhost:8080/MyWebClient/WebClient/

P.S1: in this blog, I used NAV 2016 as an example. But the same apply to all NAV versions with a web client.

P.S2: I used default installation folder. You may need to adapt this for your test.

P.S3: You try this trick on your own risk.

P.S4: I’ll let you play with it and create the whole web site from scratch 😉

This blog is available also on Microsoft Dynamics NAV Community

Dynamics NAV Generic SOAP Client

Last summer, when I posted my first article I though blogging is very easy, and I’ll post an article every week. Actually, it’s not that easy. Anyway, after few months here is the article, I promised: a 100% generic web service client for NAV.

I was looking for a way to automate all my web service calls without managing, deploying, and struggling with all Dlls generated by Visual Studio. I was hoping to use CU 1290 “SOAP Web Service Request Mgt.” like described here. I quickly noticed that it is not working if the web service comes from another NAV Database (due to SOAP version used natively by NAV). So, I started looking around how Visual Studio generates Dlls I was used to use. I found the answer in this wonderful article from msdn.

This introduction begins to be longer than expected. So, let’s get into the bare bones of the topic.

As you guessed, I tried to translate the msdn article using .NET interoperability in NAV. The result was astonishing. I let you admire the similarities:

pure-c
Pure C#
pure-cal
Pure C/AL

The C/AL code remembers me this great article. My first reaction was: What the he**, I’m writing code like the great Vjekoslav Babić.

Now, let me explain how it works. The CU uses four functions:

  1. InitClient: compiles the WSDL on the fly and prepares a ready to use client (proxy, dll… or whatever you want to call it) in memory.
  2. InitCallMethod: prepares the method to call with its parameters.
  3. CallMethod: invokes the method and retrieves the web service result.
  4. GetObjectValue: use the web service result in whatever way you want (result may be simple Text,Decimal… or complex Customer Record…).

Here is an example:

how-to-use

and this is the result:

example1

Enough talking, you can download the code here gws-with-examples.

Some readers may say:

But this needs to compile the client every time; this is huge for the memory.

This is true. The answer will be the subject of one of my next posts.

This blog is available also on Microsoft Dynamics NAV Community

My first blog post… about NAV

It’s been a few years now that I’m reading every single blog post about Dynamics NAV. I learned a lot from all the experts that they share their time with us. Thanks to them, I found answers to a lot of problems I faced in my professional life. Better, I learned enough to overcome challenges on my own.

Lately, I was thinking why not start blogging? So here I am, this is my first blog post. For sure, it is not directly about NAV as I said in the subject; and it will not give you any tip or trick as you expected.

But hey, wait for my next blog post. I already have an idea about its topic… It is about a 100% generic web service client for NAV.

This blog is available also on Microsoft Dynamics NAV Community

© 2022 NAV NAB BLOG

Theme by Anders NorenUp ↑