{"id":42710,"date":"2008-05-13T02:47:00","date_gmt":"2008-05-13T02:47:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/nav\/2008\/05\/13\/nas-tutorial\/"},"modified":"2023-05-31T15:34:17","modified_gmt":"2023-05-31T22:34:17","slug":"nas-tutorial","status":"publish","type":"post","link":"https:\/\/www.microsoft.com\/en-us\/dynamics-365\/blog\/no-audience\/2008\/05\/13\/nas-tutorial\/","title":{"rendered":"NAS Tutorial"},"content":{"rendered":"
This post is based on KB article 861762 which was previously published on PartnerSource.\u00a0This post is an updated version, and available to a wider audience (no PartnerSource login required).<\/p>\n
It describes the basics of what Navision Application Server (NAS) does, and an example of how to build a NAS application in less than 30 minutes. The KB article continued with an example of how to use NAV Communication Components and BusAdapter.<\/p>\n
What is NAS?<\/strong> It must have ID 99 (the name of the function is irrelevant) NAS on its own does not do anything else. So on its own it is a very simple component. But the application you build around it can, off course, be as complicated as any other application.<\/p>\n This tutorial will take you through the steps of building a simple application using NAS. After having completed the tutorial, I hope you will be comfortable with NAS, how to use it, and how to set it up.<\/p>\n Tutorial:<\/strong><\/p>\n 1:\u00a0 Setting NAS<\/u><\/p>\n In this tutorial we will run NAS on a SQL Server. Just like with a normal client you can do the same things against a Native server. Just use Nas.exe instead of NasSQL.exe. I assume that you already have a NAV database running on a SQL Server, and that you can open this database with a normal NAV client.<\/p>\n Install NAS from the product CD.<\/p>\n Installing NAS will automatically create two services [Machinename-CLASSIC] and [Machinename-SQL] (display name is \u201cNavision Application Server [Machinename]-CLASSIC\/SQL\u201d). There are three interfaces you can use to administer NAS: There are only two tasks that you can only achieve from the command prompt: Removing an instance (service) of NAS and adding an instance of NAS. All other tasks for administering NAS can be achieved using either of these three tools.<\/p>\n Remove the two services and add your own service:<\/u> Also note, that if you are\u00a0running on Windows Vista, then opening a normal command prompt may not give you enough permissions. So, if running on Vista, open the command prompt from the Start Menu -> All Programs -> Accessories, then right-click on “Command Prompt”, and select “Run as Administrator”.<\/p>\n To remove a service, from the command prompt in the NAS folder, type: In the same way, remove the [Machinename]-SQL service.<\/p>\n To add a service, type: This will add a service called NAS. This is the service that we will use in this tutorial. You can add as many instances of NAS as you like \u2013 each one will appear as a service. If you want to run NAS from a different folder, then just copy the NAS files into that folder, and run the command prompt commands from there.<\/p>\n Set up the NAS service;<\/u> Remember from the previous step, that the name of your NAS is “NAS”. But in Services, the display name will be “Application Server for Microsoft Dynamics NAS” if you are using version 5. Or “Navision Application Server NAS” if you are using version 4. In the next steps, use the name NAS.<\/p>\n To start NAS Manager, click Start, Programs,\u00a0Microsoft Dynamics NAV,\u00a0Navision Application Server Manager. Rightclick on “Application Server for Microsoft Dynamics NAV”, and select New -> Application Server. Then type in the name of your NAS service (“NAS”).<\/p>\n The parameters you need to set up are: Once this is done, click Apply these settings.<\/p>\n One more thing you have to do, is to associate your NAS service with a Windows account. Do this by going into services, right-click the NAS service and select Properties. On the \u201cLog On\u201d tab, under \u201cLog on as:\u201d, click This Account, and select an account. For now, you can just select the Administrator Account. In a real installation it is recommended that you create a new Windows Account and use that just for NAS. NAS can only use Windows Authentication. It cannot use database login.<\/p>\n NAS has now been set up.<\/p>\n 2:\u00a0 Changes needed in\u00a0NAV<\/strong><\/p>\n In NAV, create a Windows Login<\/u> Modify codeunit 1 IF CGNASStartedinLoop = FALSE THEN This part of the code tells NAS to do, if it logs on with Startup Parameter OSYNCH or JOBQUEUE. So, add your own parameter here, like this:<\/p>\n IF CGNASStartedinLoop = FALSE THEN You now have your NAS application, but at the moment it\u2019s not doing anything. Let\u2019s make the simplest application in the world: Put one line in this new section: Test it!<\/u> 1)\u00a0Go to Services, and (re)start the NAS Service. Just because NAS starts, it doesn\u2019t necessarily mean that it works! Make an Application using the timer trigger:<\/strong><\/p>\n Create a new codeunit. Declare one variable:<\/p>\n Name\u00a0Datatype\u00a0Suntype Set the property WithEvents to Yes on this variable. Notice the new trigger that was created.<\/p>\n Add this code: NavisionTimer.Interval := 3000; NavisionTimer::Timer(MilliSecounds : Integer) Run\u00a0 the codeunit and see that Nothing happens.\u00a0 \u2013 why is that?<\/p>\n Design the codeunit again, go to codeunit properties and set the property Singleinstance to Yes. The only way to stop a SingleInstance codeunit, is\u00a0to close or reopen the company (Ctrl+O).<\/p>\n Now go back to codeunit 1, and replace the code in function 99 with this line:<\/p>\n CODEUNIT.RUN(CODEUNIT::”Navision Timer”);<\/p>\n Because of Object Cache, NAS may not pick this change up until you restart the service. So do that, and\u00a0if everything works OK, you should now get the time in your application log every three seconds.<\/p>\n Troubleshooting NAS:<\/strong><\/p>\n Remember that NAS is just a client without a user interface. So the simplest way to troubleshoot NAS, is to run whicever codeunit it runs from a normal NAV client. You can then better see what it is doing, and you can use the normal debugging features.<\/p>\n","protected":false},"excerpt":{"rendered":" This post is based on KB article 861762 which was previously published on PartnerSource.\u00a0This post is an updated version, and available to a wider audience (no PartnerSource login required). It describes the basics of what Navision Application Server (NAS) does, and an example of how to build a NAS application in less than 30 minutes.<\/p>\n","protected":false},"author":4528,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ms_queue_id":[],"ep_exclude_from_search":false,"_classifai_error":"","_classifai_text_to_speech_error":"","footnotes":""},"post_tag":[],"product":[],"content-type":[4690],"topic":[],"audience-type":[],"audience":[],"ms-author":[],"coauthors":[4273],"class_list":["post-42710","post","type-post","status-publish","format-standard","hentry","content-type-news-and-product-updates","review-flag-1593580425-950","review-flag-1593580416-649","review-flag-2-1593580434-938","review-flag-4-1593580444-193","review-flag-5-1593580450-212","review-flag-new-1593580245-522"],"yoast_head":"\n
\nNAS is a client without a user interface (GUI), running as a service. That\u2019s all it is. When it starts, it will run a function in codeunit 1, passing on the Start-up parameter that has been set up. That\u2019s all it does. There are two prerequisites for this function in codeunit 1:<\/p>\n
\nIt must have one parameter Text 250. The name of this parameter is also irrelevant.<\/p>\n
\nGo to services and check that you can see these two services. These services are ready to use but just for the practise, the first thing we will do is to remove these two services and create our own service.<\/p>\n
\nNavision Application Server Manager (an MMC snapin)
\nWindows Registry
\nCommand prompt<\/p>\n
\nFor this task, you need to use the command prompt. Go to the folder where you installed NAS. Notice that, in this folder you will find two .exe files: Nas.exe and Nassql.exe. In the following section, use nassql.exe since we are running on a SQL Server. If you\u00a0were running NAV on Native server, you would use nas.exe. But each file has the same functionality.<\/p>\n
\nNassql appservername=[machinename]-CLASSIC, uninstallasservice .
\nThis will remove the service with the name [machinename]-CLASSIC that was installed when you installed NAS.<\/p>\n
\nNassql appservername=NAS, installasservice<\/p>\n
\nOnce you have an instance (service) of NAS, you will need to set it up. You can do this from the command prompt, but it is easier to user either the NAS manager, or Windows Registry. If you want to use Registry (Regedit), go to the key HKEY_LOCAL_MACHINE\/SYSTEM\/CurrentConotrolSet\/Services and look for your service here. We will use the NAS Manager.<\/p>\n
\nDatabase Server Name:\u00a0This is your SQL Server.
\nDatabase:\u00a0\u00a0The NAV database.
\nCompany Name: Specify the name of the Navision company. NAS must be set up to run in a specific company. If you have more than one company, you need one NAS for each company.
\nStart-up parameter:\u00a0 Specify any text string here. You can use this parameter to distinguish between multiple instances of NAS. For now, just specify \u201cNAS\u201d.
\nNet type:\u00a0 Select Default.
\nObject Cache: Specify Object Cache, or leave it as default.<\/p>\n
\nIn the previous section you set up NAS to use a Windows Account. You need to give access in NAV for this account. Go to Tools, Security, Windows Logins and specify that account here. For this exercise, click Roles and give this account role ID SUPER. Make sure to synchronize permissions (Tools -> Secutiry -> Synchronize all logins).<\/p>\n
\n<\/u>The last step is to create a function in codeunit 1. As mentioned before, NAS runs a function in codeunit 1 with the ID 99 and a parameter (text 250). In a standard NAV database, this function is called NASHandler. The code in this function depends on which version of NAV you are running, but in recent versions, it\u00a0will contain a section that looks like this:<\/p>\n
\nCASE Parameter OF
\n‘OSYNCH’,’JOBQUEUE’:
\nBEGIN
\nIF NOT JobQueueSetup.GET THEN BEGIN
\nJobQueueSetup.INIT;
\nJobQueueSetup.INSERT;
\nEND;<\/p>\n
\nCASE Parameter OF
\n‘NAS’:
\nBEGIN
\n\/\/ This is your new section, and where you will tell your NAS what to do.
\nEND;
\n‘OSYNCH’,’JOBQUEUE’:
\nBEGIN
\nIF NOT JobQueueSetup.GET THEN BEGIN
\nJobQueueSetup.INIT;
\nJobQueueSetup.INSERT;
\nEND;<\/p>\n
\nMESSAGE(\u2018NAS Has logged in!\u2019);
\nClose (and safe) the codeunit.<\/p>\n
\nNow it\u2019s time to see if everything has been set up correctly. Because NAS doesn\u2019t have a user interface, it cannot open a message box. Instead, it will put any messages from the MESSAGE command as a message in the application log (Event Viewer). Check that NAS is working by following these steps:<\/p>\n
\n2)\u00a0Open the Even Viewer (Start, Programs, Administrative tools, Even Viewer. Click \u201cApplication Log\u201d and check the latest messages here. If you see a message saying \u2018NAS Has logged in!\u2019 it means that NAS has successfully run the function in codeunit 1.<\/p>\n
\nNavisionTimer\u00a0Automation\u00a0‘Navision Timer 1.0’.Timer<\/p>\n
\nOnRun()
\nIF ISCLEAR(NavisionTimer) THEN
\nCREATE(NavisionTimer);<\/p>\n
\nNavisionTimer.Enabled := TRUE;<\/p>\n
\nMESSAGE(‘Time is %1’,TIME);<\/p>\n
\nRun the codeunit again and see the difference that this property made. SingleInstance means that the codeunit will keep running, waiting to be triggered by something – in this case, the timer.<\/p>\n