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):
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!
Comments
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.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Where is this property??? I select properties with the line selected in variables, all I get as properties are its object id and dimensions???
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
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!
When we see a post, it is often difficult to see if the person who posted it is a newby or a Navision-ace.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Normal CodeUnit (not single-instance):
I was hoping for 5 "pling"'s, but obviously I am doing something wrong. Any help appreciated!
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
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:
...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-[
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
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 write
In the Timer Trigger (it appers after you change WithEvents Property to Yes) write