Navision Timer 1.0.Timer

Matt.Hill
Member Posts: 32
I'm trying to write some some code that will run a batch of reports overnight, so far I've got NAS in place and running, but now I need to introduce an element of timing (the code needs to run during a specific time window to stop it affecting the TV channel that we run). So far I have some code (in a single instance codeunt):
However, it complains about the following line when trying to complile as being "not an allowed option":
Even to me that syntax seems a 'bit odd' but its replicated in all the examples I've found here. ](*,)
Timer is defined as being an Automation variable of 'Navision Timer 1.0.Timer'
What am I doing wrong???
Thanks in advance!
IF ISCLEAR(Timer) THEN CREATE(Timer); Interval := 60 * 15; //wake up every 15 minutes Timer.Enabled := FALSE; Timer.Interval := Interval * 1000; Timer.Enabled := TRUE; UserStartTime := 222900T; LastRunDate := 0D; Timer::Timer(Milliseconds : Integer) IF (TIME >= UserStartTime) AND (TODAY <> LastRunDate) THEN BEGIN MESSAGE('Start Time %1',TIME); REPORT.RUNMODAL(795,FALSE,FALSE); MESSAGE('End Time %1',TIME); LastRunDate := TODAY; END;
However, it complains about the following line when trying to complile as being "not an allowed option":
Timer::Timer(Milliseconds : Integer)
Even to me that syntax seems a 'bit odd' but its replicated in all the examples I've found here. ](*,)
Timer is defined as being an Automation variable of 'Navision Timer 1.0.Timer'
What am I doing wrong???
Thanks in advance!
0
Comments
-
Matt.Hill wrote:
Timer::Timer(Milliseconds : Integer)
In the global variable of the Timer-automation, you have to put its property "WithEvents" to TRUE. This will create the function. Then you put the code in it.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
kriki wrote:In the global variable of the Timer-automation, you have to put its property "WithEvents" to TRUE. This will create the function. Then you put the code in it.
Where is this property??? I select properties with the line selected in variables, all I get as properties are its object id and dimensions???0 -
Matt.Hill wrote:kriki wrote:In the global variable of the Timer-automation, you have to put its property "WithEvents" to TRUE. This will create the function. Then you put the code in it.
Where is this property??? I select properties with the line selected in variables, all I get as properties are its object id and dimensions???Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
kriki wrote:Open the global variables. Position the cursor on the Timer-automation. Hit Shift+F4. This opens the properties of the variable. And there it is.
Calm down...I know how to get to the properties of a variable....
It wasn't in the list of options...seems that it needed to be a global (not local)...oh well!
Anyhow...all fixed!0 -
Matt.Hill wrote:kriki wrote:Open the global variables. Position the cursor on the Timer-automation. Hit Shift+F4. This opens the properties of the variable. And there it is.
Calm down...
When we see a post, it is often difficult to see if the person who posted it is a newby or a Navision-ace.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!1 -
I am new to Automations with WithEvents and am having problems when testing this timer.
Normal CodeUnit (not single-instance):OnRun() IF ISCLEAR(Timer) THEN CREATE(Timer); Timer.Interval := 1000; Timer.Enabled := TRUE; SLEEP(5000); Timer::Timer(Milliseconds : Integer) MESSAGE('pling');
I was hoping for 5 "pling"'s, but obviously I am doing something wrong. Any help appreciated!NAVN00b0 -
Codeunit must be single instance, because it need to remain in memory. If you do not set this property, codeunit do the code in OnRun trigger and then clears all variables and is removed from memory.0
-
During the sleep, the process is still running and it is why the event is not called. Sleep does not mean that the "thread" is sleeping or something, it is just frozen for the amount of time and other applications can do something. But not Nav client itself...0
-
Thanks for answering!
I was indeed hoping that the event would trigger during the sleep in a multithreaded fashion, but in retrospect I see that I was hoping for too much!
Changing the CodeUnit to SingleInstance makes the timer work, but it only triggers when the codeunit is not processing any other code.
For example, writing:OnRun() IF ISCLEAR(Timer) THEN CREATE(Timer); Timer.Interval := 3000; Timer.Enabled := TRUE; REPEAT i := i+1 UNTIL i>10000000;
...causes the timer-event to trigger only after the loop has finished.
So to me it seems like Automation-events in Navision need to be in a Single-Instance CodeUnit, and that they will only trigger when the codeunit is "idling" - that is, not currently performing any other code.
Any comments welcome! 8-[NAVN00b0 -
Yes, this is a way how NAV works. One thread, if running, other events are suspended. (But, if you do some tests, you can see that the timer event wait in some queue and is processed after the running thread ends. I wrote some example of this in one thread on this forum).0
-
Hi, I posted a solution here http://stackoverflow.com/questions/17827347/time-scheduling-in-navision-with-timer
This example runs at 7:40, 12:40 and 16:40 each day.
Using the Navision Timer 1.0 NAVTimer Automation 'Navision Timer 1.0'.Timer
Set the Property 'WithEvents' of the NAVTimer to Yes
Set the Property 'SingleInstance' of the Codeunit, if you using one, to Yes
In the On Run Trigger writeIF ISCLEAR(NAVTimer) THEN CREATE(NAVTimer); NAVTimer.Interval := 1 * 60000; // Important! set to 1 Minute NAVTimer.Enabled := TRUE;
In the Timer Trigger (it appers after you change WithEvents Property to Yes) writesTime := COPYSTR(FORMAT(TIME), 1, 5); // Cut seconds sHour := COPYSTR(sTime, 1, 2); sMinute := COPYSTR(sTime, 4, 2); IF sHour IN ['07','12','16'] THEN IF sMinute = '40' THEN IF NOT CODEUNIT.RUN(CODEUNIT::xxx) THEN;
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions