If you are a user with multiple companies in your NAV database, or even with multiple databases you might be used to switching between companies or servers.

I  have been asked to create desktop shortcuts for the users.  What if the user is acting as a sales person in one company and as an accountant in another.  Then there is this confirmation dialog that always requires us to approve the server connection.  This is a process that takes time.

So, why don’t we let the user do this by him self ?

I wanted to so I created the code to make this happen.  First I needed to add a function to Codeunit 9500, Debugger Management.

[code] PROCEDURE GetConfigDetails@50000(VAR ServerComputerName@50002 : Text;VAR ServerInstance@50001 : Text;VAR ServerPort@50000 : Text;VAR ConfigFileName@50003 : Text);
BEGIN
IF ISNULL(Config) THEN
Config := Config.Instance;
ServerComputerName := Config.GetStringSetting(‘Server’);
ServerInstance := Config.GetStringSetting(‘ServerInstance’);
ServerPort := Config.GetStringSetting(‘ClientServicesPort’);
IF Config.Configuration.HasFile THEN
ConfigFileName := Config.Configuration.FilePath;
END;

[/code]

and then a small Codeunit to do the magic.  And guess what, no confirmation dialogs.

[code]OBJECT Codeunit 50001 Create Desktop Shortcut
{
OBJECT-PROPERTIES
{
Date=10.10.13;
Time=15:23:43;
Modified=Yes;
Version List=Dynamics.is;
}
PROPERTIES
{
OnRun=VAR
SpecialFolder@50006 : DotNet "’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.System.Environment+SpecialFolder" RUNONCLIENT;
Environment@50007 : DotNet "’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.System.Environment" RUNONCLIENT;
httpUtility@50001 : DotNet "’System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.System.Web.HttpUtility";
UrlString@50005 : Text;
ServerComputerName@50004 : Text;
ServerInstance@50003 : Text;
ServerPort@50002 : Text;
ConfigFileName@50000 : Text;
Arguments@50008 : Text;
LinkName@50009 : Text;
BEGIN
DebugMgt.GetConfigDetails(ServerComputerName,ServerInstance,ServerPort,ConfigFileName);
UrlString := STRSUBSTNO(‘DynamicsNAV://%1:%2/%3/%4/’,ServerComputerName,ServerPort,ServerInstance,httpUtility.UrlPathEncode(COMPANYNAME));

CREATE(WshShell,TRUE,TRUE);
LinkName := Environment.GetFolderPath(SpecialFolder.DesktopDirectory) + ‘\’ + COMPANYNAME;
IF ConfigFileName <> ” THEN
Arguments := STRSUBSTNO(‘ -settings:"%1" %2’,ConfigFileName,UrlString)
ELSE
Arguments := STRSUBSTNO(‘ -protocolhandler "%1"’,UrlString);

ActiveSession.SETRANGE("Session ID",SESSIONID);
ActiveSession.FINDFIRST;
Personalization.GET(ActiveSession."User SID");
IF Personalization."Language ID" <> 0 THEN
Arguments := STRSUBSTNO(‘ -language:%1 ‘,Personalization."Language ID") + Arguments;
IF Personalization."Profile ID" <> ” THEN BEGIN
Profile.GET(Personalization."Profile ID");
Arguments := STRSUBSTNO(‘ -profile:"%1" ‘,Personalization."Profile ID") + Arguments;
LinkName := LinkName + ‘ ‘ + Profile.Description;
END;

WshShortcut := WshShell.CreateShortcut(LinkName + ‘.lnk’);
WshShortcut.TargetPath := GetClientFileName;
WshShortcut.Arguments := Arguments;
WshShortcut.Description := COMPANYNAME;
WshShortcut.WorkingDirectory := Path.GetDirectoryName(GetClientFileName);
WshShortcut.Save;
CLEAR(WshShortcut);
CLEAR(WshShell);
END;

}
CODE
{
VAR
WshShortcut@50005 : Automation "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 1.0:{A548B8E4-51D5-4661-8824-DAA1D893DFB2}:’Windows Script Host Object Model’.WshShortcut";
WshShell@50000 : Automation "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 1.0:{72C24DD5-D70A-438B-8A42-98424B88AFB8}:’Windows Script Host Object Model’.WshShell";
Path@50001 : DotNet "’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.System.IO.Path" RUNONCLIENT;
Personalization@50003 : Record 2000000073;
ActiveSession@50004 : Record 2000000110;
Profile@50006 : Record 2000000072;
DebugMgt@50002 : Codeunit 9500;

PROCEDURE GetClientFileName@50018() ClientFileName : Text;
VAR
Assembly@50006 : DotNet "’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.System.Reflection.Assembly" RUNONCLIENT;
BEGIN
Assembly := Assembly.GetCallingAssembly;
ClientFileName := Path.GetDirectoryName(Assembly.Location) + ‘\Microsoft.Dynamics.Nav.Client.exe’;
END;

BEGIN
END.
}
}

[/code]

By running this Codeunit a shortcut will be created on the user desktop. The shortcut name will be the company name and the profile description. I guess it is not to hard to code the making of shortcuts for the developement environment but I leave that to you.

Create Desktop Shortcut

2 thoughts on “Creating a desktop shortcut for Dynamics NAV 2013 (R2)

  1. microlabs says:

    Thanks for sharing such informative blog. please share some more information in your next blog. I would like to read it.

Leave a Reply

%d bloggers like this: