NAS and Timer

Hello

I have been reading a lot of NAS and ‘Navision Timer 1.0’.Timer but I still can put it all together. I miss the whole picture

Lets say we have a codeunit with some code i want to be activated every 30 min every day.

Is it the timer which start NAS and then activate the codeunit?

Or is it the NAS which start the timer and then active the codeunit?

I know everything about how codeunit 1 is called and so on but I think I just miss this basic understanding.

Michael

NAS is nothing more than a NAV session that runs without a user interface. When its connection opens, the NASHandler function in codeunit 1 is fired, and depending on the NAS startup parameter it then executes whatever code is programmed for that startup parameter.

A common practice is to start a single instance codeunit, which in turn contains the functionality for that startup parameter. This might be a timer, a TCP/IP port, a MSMQ monitor, anything that you need really. So in case of a timer: NAS connects to the database, the NASHandler function in codeunit 1 fires, which in turn runs a single instance codeunit. This single instance codeunit will then have code in the OnRun trigger to initialize and start the timer.

You can check out a standard Cronus database for a variety of examples.

Here’s a very simple example:

Create a codeunit. Enter this global variable:
Name DataType Subtype
NavisionTimer Automation ‘Navision Timer 1.0’.Timer
Make sure the “WithEvents” property for this variable is “Yes”.

Enter this code:

Trigger - OnRun()
IF ISCLEAR(NavisionTimer) THEN
CREATE(NavisionTimer);
NavisionTimer.Interval := 3000;
NavisionTimer.Enabled := TRUE;

Trigger - NavisionTimer::Timer(Milliseconds : Integer)
MESSAGE(‘The current time is: %1’,TIME);

You may have to close and save the codeunit before the NavisionTimer::Timer(Milliseconds : Integer) trigger becomes available.
Make sure that the codeunit property “SingleInstance” is “Yes”.
Remember when you start this it will run until you close NAV so have everything saved and ready to go.
It should pop up a message box with the time every 3 seconds.

Thank you, DenSter (and DigiTecKik)

You wrote: “…,which in turn runs a single instance codeunit”. Does it mean that codeunit 1 fires up all the time or only ones? And then starts the single instance codeunit many times?

Single instance codeunits don’t get destroyed, there is only one instance per session. It’s almost abstract how you have to think about it. When any function in a single instance codeunit is run, the system creates ONE instance of that codeunit and keeps it in memory. Any time that any object refers to that codeunit, it will refer to that one instance.

So say you have a SI codeunit that sets an integer variable to 2. Say you run that from the customer card. If you were to look at that variable from the vendor card, the variable would still have that same value. Obviously both forms are different objects, and they have different variables, but because the codeunit is “single instance” they refer to the same thing in memory.

So for these NAS codeunits what happens is they have something in them that starts a process that can run for long periods of time, or they open a connection that can react to events. A timer is one example of what you can do in a single instance codeunit.

Codeunit 1 is a single instance codeunit itself. When you log into an NAV client, some of the CU1 functions are fired. When it’s NAS that logs in, it fires the ‘NASHandler’ function, and that is used to give the developer a way of programming the system what needs to happen for each NAS startup parameter. You could program the system to run 600 codeunits if you wanted to, and each “single instance” codeunit would then remain in memory until the session is closed.

Hey DenSter

Thank you again. I have to think about it and look on some examples. But Im very close to have a full understanding of how NAS works.

Nas will run this Code if I put these under Function ID 99

.

I want that I will not execute Codeunit but Nav will start this.

How to achieve this? Kindly reply

Dear DigiTecKid

I have create a codeunit as you said and add my code under MESSAGE(‘The current time is: %1’,TIME);.

My Code is :

IF IdleSession.FINDSET THEN
REPEAT
IF (NOT IdleSession.“My Session”) AND (IdleSession.“Idle Time” >3) THEN
IdleSession.DELETE;
UNTIL IdleSession.NEXT =0;

But Problem is That it kill my Session which I don’t want.

How to achieve this ?? Kindly reply.