.NET Interop—I’m Lovin’ It!

If this was a blog about grammar, I might be asking whether a verb like “to love” can be conjugated in a progressive tense to give us the phrase “I’m Lovin’ It”. But it’s not, it’s a blog about Dynamics NAV and I’m writing about .NET Interop in Dynamics NAV 2009 R2 which has got to be the coolest feature for NAV ever!

Let’s assume that you’re into Dynamics NAV and not dynamic verbs. The question I’m really asking here is how do you find the temporary path in Dynamics NAV? Easy, I hear your shout. You just use ENVIRON(‘TEMP’);

Aha, but what if you’re using the RoleTailored client and you want to find the temp directory on the client? If you try using the ENVIRON command you’ll get the following error message:

image

Previously I solved this problem in quite a convoluted way. I created a temporary file (albeit an empty one) in the temporary path on the NAV Server, then I transferred it to the client using the  magic path, then I found the path of the location of the file where it got transferred to.

Does that sound crazy? Take a look at the ClientTempFileName() function in the 3-Tier Automation Mgt. codeunit if you don’t believe me. I used that function to get a client temporary file and then used  the Path function to find the client temporary file path.

But now with the .NET Interop there is a better way.

Simply create a local variable of type DotNet and Subtype 'mscorlib'.System.Environment. Make sure you bring up the properties of the variable and set the RunOnClient property to Yes.

Now you can write code like this:


IF ISSERVICETIER THEN
  MESSAGE('Temp is %1',dnEnvironment.GetEnvironmentVariable('temp'))
ELSE
  MESSAGE('Temp is %1',ENVIRON('temp'));
EXIT;

 

Aaah. I’m Lovin’ It!

 

P.S. If you’re more interested in grammar than Dynamics NAV, check out http://grammar.quickanddirtytips.com/im-loving-it-grammar.aspx to find out why McDonald’s slogan is such bad grammar.


Related
Recommended