Host Name

In Dynamics NAV applications I sometimes use the client host name to store settings or as a filter.  Until now I have been using the ENVIRON function but it is not available in NAV 2009.

I have now solved this issue with the following function that will also work in Role Tailored Client.
[code]IF ISCLEAR(WShell) THEN
CREATE(WShell,TRUE,TRUE);
EnviormentPath := ‘PROCESS’;
WEnviroment := WShell.Environment(EnviormentPath);
IF UPPERCASE(WEnviroment.Item(‘SESSIONNAME’)) = ‘CONSOLE’ THEN
ComputerName := WEnviroment.Item(‘COMPUTERNAME’)
ELSE
ComputerName := WEnviroment.Item(‘CLIENTNAME’)[/code]
Where

Name DataType Subtype
WShell Automation ‘Windows Script Host Object Model’.WshShell
WEnviroment Automation ‘Windows Script Host Object Model’.WshEnvironment
EnviormentPath Code[10]

Unzip Files

By using the Automation “‘Microsoft Shell Controls And Automation’.Shell” you can unzip a file within Dynamics NAV.

Create a Global

Name DataType Subtype
SystemShellControl Automation ‘Microsoft Shell Controls And Automation’.Shell
SystemShellItem Automation ‘Microsoft Shell Controls And Automation’.FolderItem
SystemShellItems Automation ‘Microsoft Shell Controls And Automation’.FolderItems
FileName Text
ZipFileName Text
DestFolderName Text
Index Integer
Pos Integer

And then simply
[code]ZipFileName := ‘C:\TEMP\ZipFile.Zip’;
DestFolderName := ‘C:\TEMP\’;
SystemShellItems := SystemShellControl.NameSpace(ZipFileName).Items;
SystemShellControl.NameSpace(DestFolderName).CopyHere(SystemShellItems);
FOR Index := 1 TO SystemShellItems.Count DO BEGIN
SystemShellItem := SystemShellItems.Item(Index – 1);
IF ISSERVICETIER THEN
FileName := SystemShellItem.Path
ELSE
FOR Pos := 1 TO STRLEN(SystemShellItem.Path) DO
IF COPYSTR(SystemShellItem.Path,Pos,1) = ‘\’ THEN
FileName := COPYSTR(SystemShellItem.Path,Pos + 1);
// Do what ever you whant to DestFolderName + FileName
END;[/code]

Download a File

In Dynamic NAV it is possible to use the Automation “‘Microsoft XML, v6.0’.XMLHTTP” to download files.  The code would be
[code]IF ISCLEAR(WinHTTP) THEN
CREATE(WinHTTP,TRUE,FALSE);

WinHTTP.open(‘GET’,URL,FALSE);
WinHTTP.send(”);

IF WinHTTP.status <> 200 THEN
ERROR(Text003,WinHTTP.status,WinHTTP.statusText);

TempFile.CREATE(TempFileName);
TempFile.CREATEOUTSTREAM(OutStr);
InStr := WinHTTP.responseStream;
COPYSTREAM(OutStr,InStr);
TempFile.CLOSE;[/code]
Where Text003 is “Status error %1 %2”

The URL will be downloaded to the filename “TempFileName”

Add Namespaces to outgoing XML

The tax authority in Iceland are using Soap web services.  I have built XML Ports in NAV to create the request XML and another one to read the response XML.

I already wrote about using stylesheet to strip namespaces from the incoming XML before passing it to the XML Port.  I previously just added namespaces to the outgoing XML with attributes in the request XML Port.  This does not work in Role Tailored Client.

The solution was to remove all the namespaces attributes from the request XML Ports and create a function to add namespaces to the XML before passing it to the web server.  This work both in Classic Client and in Role Tailored Client.

AddNameSpaces source code