None form related timers - are they possible in 4.0?

In Nav 4.0 is there anyway of creating a timer event which is not linked to a form. On previous posts I have seem mention of timer events on codeunits – is this still possible on 4.0 and if so how?

Many Thanks


You need to use the Navision timer dll (‘Navision Timer 1.0’.Timer).

Create a singleinstance codeunit, and put this code in the OnRun-trigger.

autNavisionTimer.Interval(recSetup.“NAS Timer Interval (s)” * 1000);

When you run the codeunit, it remains in memory and the “autNavisionTimer::Timer(Milliseconds : Integer)” will be called by the system every N milliseconds.

Hi Kriki,

Thanks for the quick response but I think my own scripting knowledge may be letting me down. Could you answer another couple of questions?

What type of object is autNavisionTimer?

How do I define it as a variable, so that I can reference it in script?

Can this run on a client or does it need to run on NAS?

Many Thanks


Hey Andy,

See below


You can also run it on a client. Remember that the NAS is a client without GUI.

Hi Kriki,

Thanks for the response.

Unfortunately I don’t get an option of data type automatic. Maybe I don’t have the correct version or the correct programming license!!

It is data type Automation.

Remember to create is as local or global. It won’t appear as datatype for a field in a table.

Still not there, this is a list of the options it gives me

sorry my screen shot did not appear, but the option does not exists.

Hey Andy,

Gonna ask some standard question’s here. I am at home now, and won’t be at work for 3 days, but it might help someone else help you.

What type of database and what version.

Do you have a developer license or end user?


Sorry, I mean that I don’t have Navision installed at home.


The database is sqlserver 2000. I’m not sure how you classify the license I can create codeunits, xmldataports etc and script on most objects, but I can not alter posting codeunits or update invoicing tables.

As another line of enquiry I have only just discovered that you can set a form to be non visible, but it still responds to timer events. I have coded the form to run through the company initialize code unit and am then using the timer event from the form. As the form is invisible the user can not shut it down. Has anyone else try this approach and know of any dangers etc associated. BTW the reason I am doing this is to capture when users have been inactive for a certain time and kick them of the system.



No need to do all that.

In File=>Database=>Tab Sessions=>Dropdown on field “Current Sessions”, there is a field “Idle Time”. You can use that to check how long they have been idle. To kick them out, you just need to delete the record.

Is this possible without user interaction?

Hi Kriki and Sander7,

I agree with both posts I could use the file sessions removal to remove users, which I use at the moment. The problem with this being that I have to be physically at my desk to perform this task.

The invisible form window seems to work but I can’t get it to remove the session. I have implemented the following code

IF lr_session.FIND(’-’) THEN


// for each record see what the idle time is

// and check that they are not a reserved user

IF ( lr_session.“Idle Time” > 2500000 )

AND (lr_session.“User ID” <> ‘sa’)

AND (lr_session.“User ID” <> ‘Administrator’)THEN


UNTIL lr_session.NEXT = 0;

Where lr_session is a record relating to table 2000000009

The basics of the code work, in as much that it identifies users who have been idle for a while, but the delete itself returns an error specifying that the country code is invalid.

I can understand why this is causing an error as I am not really trying to delete the record, but instead in SQL terms trying to issue a KILL command. Is there a way to do this from within Navision?



Sorry programming error, the code should be

IF ( lr_session.“Idle Time” > 2500000 )

AND (lr_session.“User ID” <> ‘sa’)

AND (lr_session.“User ID” <> ‘Administrator’)THEN

lr_session.DELETE(TRUE); // difference is here

UNTIL lr_session.NEXT = 0;

The error was coming from deleting from the table that the form was based on.

With this code there is no error and the session record is deleted but this does not actually delete the users all it does is reset the user record, so the idle counter starts again


Hi Andy,

Actually I was only asking Alain if it could be done, since I didn’t know that.

As You state yourself, I would expect that You would have to sit by the Screen all day, or create some timer-thingey after all.

Shouldn’t You adress lr_session in Your DELETE-statement (lr_session.DELETE(TRUE))

Maybe you should think about creating a job in SQL to do this for you. After all, you are on SQL.

There are a few pure SQL forums you can check out:

Probably someone already has a SQL job that just does that.

And maybe also in the SQL online books, you can find something to do it.

Kriki and sander7,

Agreed I think that sql may be the best bet. A scheduled sql task may yield more of a result. I will go and investigate and report anything of interest back – it may be sometime!!!

I still think the invisible form has some merit to it. Maybe as a messaging agent, order dispatch etc

Thanks for all your help