Posts

Getting started with NAV and .Net Interop – Part 4

Afbeelding
Once more into the breach Jeez, Part 4 already? Last time in Part 3 we imported files using streams and learned a bit more about .Net and our stamina to read boring code. The previous example was a tad bigger than the first one, but now we’ll wrap that into an even bigger example! Exampleception !! Import all files in a folder We have all done this before . When you want to import a file you make a Record variable on the File record. Filter it, loop over it, build your filename, and import it. Something like this: lv_ImportPath := 'C:\Import'; //You get this from Setup or the user of course //Filter lt_Files.SETRANGE(Path,lv_ImportPath); lt_Files.SETRANGE("Is a file",TRUE); lt_Files.SETFILTER(Name,'*.csv'); //Loop IF lt_Files.FINDSET THEN BEGIN   REPEAT     //Build file path and import file   UNTIL lt_Files.NEXT = 0; END; I’ve always found this solution clunky when it works. Sometimes it won’t. We can do better rig...

Getting started with NAV and .Net Interop – Part 3

Afbeelding
Taking it further After showing in Part 2 how to take the simplest piece of C# code and walk through the process of converting it to C/AL it’s time we crank it up a notch (see what I did there? J ). Importing a single file with streams First off something we’ve all done since Dataports left us and XMLPorts refused to import from a filename directly: lf_File.OPEN(lv_FilePath); lf_File.CREATEINSTREAM(lis_); lx_MyXMLPort.SETSOURCE(lis_); lx_MyXMLPort.IMPORT; lf_File.CLOSE; Opening the stream We can Google for “ c# create stream from file ” and find this page . With that we see we need to use the FileStream class, instantiate it by calling the constructor with some parameters and close it. Not entirely unlike what we do in our C/AL sample… [C#] using System.IO; FileStream fileStream = new FileStream ( @"c:\file.txt" , FileMode .Open); try {   // read from file or write to file } finally {   fileStream.Close(); } Enumerations are a pain i...

Getting started with NAV and .Net Interop – Part 2

Afbeelding
Long overdue So here’s Part 2. It took me some time to get off the ground since I had to rebuild my VM-infrastructure. I’m now running the database on a SQL 2012 VM with the NAV 2013 R2 Update 7 Service, clients, webclients and help-server running on a separate RDS Server VM. Each powered by an awe-inspiring 1 GB of Memory J . Thanks to BizSpark for the licenses ! Coding conventions and other disclaimers I’m going to preface these articles with a disclaimer that my code uses the code formatting as customary at my employer Edan Business Solutions without whom this article would not have been possible. It’s easiest for me and helps differentiate variables from keywords. I don’t mind discussing the finer points of this decision in the comment section, but know that it is unlikely to change my opinion (as my dear wife can attest, I’m quite stubborn on a lot of topics J ). Also, .Net Interop will only work when running in an RTC-context (this includes webservices). The Cl...

Getting started with NAV and .Net Interop – Part 1

Afbeelding
The Fear Since .Net Interop was announced in NAV 2009 R2 there has been an uneasy vibe going around amongst the “developmentally inclined” (new term, just invented). People had heard of this “.Net” thing. They knew it had something to do with programming OUTSIDE of Navision. These are often the same people still insisting on calling it Navision instead of NAV. And, as we all know, any code kept OUTSIDE (shudder) of Navision is A Bad Thing ™. It doesn’t help to say it’s somewhat like Automation. Automation is what’s causing those annoying errors when this library or that tool hasn’t been installed on your machine and blocking from testing that feature or simply compiling your code (*cough* Excel Buffer table *cough*). So no, relating .Net Interop to Automation is NOT a good idea. Or should at least be attempted with care. Because there are level headed developers out there. They want to get to know this thing people are raving about. But, if you don’t know .Net, how can you st...