NAS

Hi, Can someone please explain how NAS works in a nut shell? How the NASHandler function being called and in what duration? Does the NASHandler function get called repeatedly by the service until the service is stop or what? Also, I was able to install NAS and started the service. However, it doesn’t seem to be calling NASHandler function. I added some test code in the function and I am not getting the expected result. Unfortunately, the NAS documentation doesn’t explain this part. It only talked about how to install and setup. Thanks for the help in advance. Tri

NAS effectively is just a GUI-less Navision Client. When NAS is started it looks at the NASHandler function in Codeunit 1. In the NAS configuration webpage you specify one (or more) parameters. (If you use more than one they must be comma seperated with no spaces). The NASHandler function looks in the Case statement for the specified parameters and call the applicable codeunit(s). Without a parameter being specified NAS will not start correctly. The NASHandler function is only called one at start-up, not repeatedly. If you take a look at the Mail Handler codeunit (6220) used by NAS for the Exchange E-mail logging you will see a CAL Global automation variable CP Timer. This is used to repeatedly call the function at the specified interval. Hint: the codeunit needs to be set to SingleInstance for this to work. If you want to debug a NAS function use the message statement in you code. Each message will get logged as an event in the Windows application log on the machine running the NAS service. Hope this helps and fills in a few of the gaps in the NAS documenation.

Thanks Gary. I will play with it some more.

quote:

NAS effectively is just a GUI-less Navision Client. When NAS is started it looks at the NASHandler function in Codeunit 1. In the NAS configuration webpage you specify one (or more) parameters. (If you use more than one they must be comma seperated with no spaces). The NASHandler function looks in the Case statement for the specified parameters and call the applicable codeunit(s). Without a parameter being specified NAS will not start correctly. The NASHandler function is only called one at start-up, not repeatedly. If you take a look at the Mail Handler codeunit (6220) used by NAS for the Exchange E-mail logging you will see a CAL Global automation variable CP Timer. This is used to repeatedly call the function at the specified interval. Hint: the codeunit needs to be set to SingleInstance for this to work. If you want to debug a NAS function use the message statement in you code. Each message will get logged as an event in the Windows application log on the machine running the NAS service. Hope this helps and fills in a few of the gaps in the NAS documenation.
Originally posted by GaryFrostick - 2005 May 05 : 13:25:27

Three tips that can really help you when you are new to NAS: 1. Test the codeunit that you intend to run from the NAS as a Navision client to debug the codeunit. It will help you to run it on the NAS machine making sure that the NAS service is not running. 2. Early in development, place a Message command such as “NAS is running” in the OnRun trigger of the Single Instance codeunit you will be creating. 3. Remember when running the single instance codeunit you will need to initialize the variables yourself as they will retain their values as long as the session is running.

You might want to take a look at this introductory article on the NAS. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnav/html/TkNavision.asp

Does anyone know if a Trigger is called inside Navision when the NAS Service is stopped?

You can also start NAS from a command line and have it run with the debugger on.

Sounds interesting, can you describe how I do it?

quote:

Sounds interesting, can you describe how I do it?
Originally posted by The Duke - 2005 Aug 17 : 03:40:28

From the command line in the folder where NAS.exe resides: nas debug, startupparameter=“NAS TEST”, servername=SERVERNAME, company=“Compnay Name” Using, of course, the proper values for the startup parameter, server name, and company name.

Pretty smart, but unfotunately it didn’t show if any triggers were called when i closed the nasclient.

even if NASHandler function is empty, the service does not stop immediatelly after startup. does anyone know how to stop service (or actually, NAS is started from command line - such case) from the handler procedure?

All that the service does is start a Navision version and send the startup parameter into the NASHandler. What that function DOES is something that YOU will have to define. Since the service is a GUI-less session, you have to start up something automatic. The way this is usually implemented in Navision is by starting a so-called single instance codeunit, which is a background process. Browse codeunit 1 and find the NASHandler function. You should find the following code in there: CASE Parameter OF ‘MAILLOG’: CODEUNIT.RUN(CODEUNIT::“E-Mail Dispatcher”); // END; The parameter MAILLOG makes it so that NASHandler knows to fire the E-Mail Dispatcher codeunit, which is a single instance codeunit that handles the email logging functionality. A single instance codeunit is simply an object that is alive as long as the session is running. You can run a single instance codeunit from a regular client session as well (which you’d do while testing your NAS code). You would still have to create an object within the single instance codeunit that has events that can fire at controlled moments. Examples of these objects is the Navision communication component, to which you can attach a message queue adapter that has a MessageReceived event, or you can start a timer object that has a Timer event that fires at specified intervals. After NASHandler is done doing whatever is defined within the parameter, it is done processing, it’s the single instance codeunit that actually does the work. Neither one monitors the status of the service though. I don’t think there is no trigger within Navision that fires when the service is stopped, but to make sure you should try to start the service in debug mode and see if it does something when it is stopped.

Consider thisthe following situation. Codeunit 1 (NAS Func) … IF Parameter = NAS THEN BEGIN NASRec.GET(PrimaryKey); NASRec.“Started at” := CURRENTDATETIME; NASRec.Modify; SingleInstanceNASFunc.RUN; END; Does anyone have a suggestion to wher I can insert NASRec.GET(PrimaryKey); NASRec.“Stopped at” := CURRENTDATETIME; NASRec.Modify;

I do not have much experience with the nas but if al it does is 1. Log In 2. Run the Codeunit SingleInstanceNASFunc 3. Log out Then you can try Codeunit 1 (NAS Func) … IF Parameter = NAS THEN BEGIN NASRec.GET(PrimaryKey); NASRec.“Started at” := CURRENTDATETIME; IF SingleInstanceNASFunc.RUN THEN; NASRec.“Stopped at” := CURRENTDATETIME; NASRec.Modify; END; Remember that running a codeunit with IF statement makes it MODAL. so don’t put any modifies before it.

I will repeat my suggestion… Run NAS with the debugger (read the manual how to do this). Start it and stop it while stepping through the debugger. The purpose of this would be to see if NAS also runs through the logout functions in CU1, and if you can use that to store the stop time. The NASHandler function is probably not the place to do this, and I don’t think I would do the IF statement around a single instance codeunit. That makes it modal and it wont give control back to CU 1 until the single instance codeunit is destroyed, which is when the session is closed, which is when the service is stopped. I don’t think that would be a good idea.