Navision developper

houssayen
Member Posts: 45
Hi,
I have a problem in my project,
I developed a codeunit that accesses a text file located on a directory in my desktop and do more treatments, and for that I specify the path in the code C / AL, if not I run it automatically NAS, Everything works well,
date the account is good, now I'll specify my problem:
instead of working on a single text file, I want the treatment will be applied every time I create a new text file in this directory, In Another word, a small test at the codeunit that checks if a newtext file in this directory to execute the codeunit on it ..
THANKS ..
I have a problem in my project,
I developed a codeunit that accesses a text file located on a directory in my desktop and do more treatments, and for that I specify the path in the code C / AL, if not I run it automatically NAS, Everything works well,
date the account is good, now I'll specify my problem:
instead of working on a single text file, I want the treatment will be applied every time I create a new text file in this directory, In Another word, a small test at the codeunit that checks if a newtext file in this directory to execute the codeunit on it ..
THANKS ..
0
Comments
-
[Can you give a more meaningful title to your topic. This is more a topic-title for a joboffer.]Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Create new files in your directory as filename + date..then you can get the path through C/AL code like this
Filename := 'C:\text' + DELCHR(Format(TODAY),'=','/') + '.txt'; Message('%1',Filename);
0 -
thanks for your help, but you can tell me what that mean:
"Create new files in your directory as filename + date", can you give me an example to understand better now "filename + date"?0 -
Create Files Names in your directory astest010111.txt which means test + Date(01/01/11)
test020111.txt which means test + Date(02/01/11)
you can read the same file name through CAL code as i mentioned in previous post.0 -
thanks , but it does not work, the codeunit is blocked at the opening of the file, it gives me an error that tells me to check chemain file, here is the code associate with the opening of the file: ( the directory is called project), and my text file called "cmd16052011"
InFile.WRITEMODE: = FALSE;
InFile.TEXTMODE: = TRUE;
Filename: = 'C: \ Users \ Administrator \ Desktop \ project + DELCHR (FORMAT (TODAY ),'=','/') + '. txt ';
InFile.OPEN (Filename);
I feel you can help me..
thanks..0 -
What is your file name at C: \ Users \ Administrator \ Desktop?0
-
it's resolved
but this idea that it works if I add one file per day, but if I did create several files in the same day, how can I do?
thanks for your help..;)0 -
Hi
You can Use NAVISION TIMER automation to import data in regular interval of time.
You have a lot of information here
viewtopic.php?f=23&t=40346&start=0&hilit=timer+automation
viewtopic.php?f=23&t=36032&hilit=timer+automation
Bye0 -
thanks for your help, my aim is Not problem at the SIN and synchronizing the execution of codeunit, but my problem and at the codeunit himself, Mr. Mohanna help me much, and with his help, because my codeunit access to a single file per day according to the current date as indicated above, I know if I have the case file by adding several days, how?? : (0
-
Hi
Use this TIMER automation with a FILE record.
You can read each 5 minutes (for example) if new files are stored in your directory.
Example codeunit
Variables
Name DataType Subtype
Timer Automation 'Navision Timer 1.0'.Timer
TFile Record File[b]OnRun()[/b] IF ISCLEAR(Timer) THEN BEGIN CREATE(Timer); Timer.Interval := 300000; Timer.Enabled := TRUE; END; [b]Timer::Timer(Milliseconds : Integer)[/b] TFile.reset; TFile.setrange(Path,YourPath); TFile.setrange("Is a file",TRUE); if Tfile.find('-') then repeat // Run your import code // After data are imported, move your file to othe folder. until TFile.next=0;
Change SINGLEISTANCE property to TRUE and call it from NAS (Codeunit 1 function 99).
Bye0 -
thanks, your idea it's very important , but should not even touch the text file level directory, ie I have no right to move any files outside the directory, because my project at the end of storytelling will be executed by the NAS in missed user..:(0
-
Hi
You can rename your files name, "IMP-Oldname.txt".
Inside repeat loop, you can put a
IF copystr(TFile.Name,1,3)<>'IMP' then
BEGIN
// import data
NewFile:='IMP-'+Tfile.Name;
File.Rename(Tfile.Path+Tfile.Name,Tfile.Path+NewFile);
END;
Bye0 -
you really impress me with your ideas, thaks a lot for your help, I found that it is better that the file should be deleted after treatment for a better optimality, I began to acquire your previous idea, but I not include the following line how I will run:
Timer:: Timer (Milliseconds: Integer) [/ b]
you can m'expliquée if you like it more precisely?
thanks..0 -
Hi
This Line is TIMER automation's event.
Go to Timer variable PROPERTIES and change WITH EVENTS properti to YES.
This line will appear.
Bye0 -
oki , thanks ,
and i have Another question please, My directory named PROJECT, He Is in my desktop, so I do a little test to see how it works, but it does not work: (:
Tfile.SETRANGE (Path, 'C: \ Users \ Administrator \ Desktop \ DRAFT \ B_C');
Tfile.SETRANGE ("Is a file", TRUE);
('-') THEN BEGIN IF Tfile.FIND
test: = COPYSTR (Tfile.Name, 1.3);
MESSAGE ('the name of file is:% 1', Tfile.Name) END;
it makes me a message as result: the name of file is:
it does not give me the name of my file ..0 -
houssayen wrote:My directory named PROJECT, He Is in my desktop,
Tfile.SETRANGE (Path, 'C: \ Users \ Administrator \ Desktop \ DRAFT \ B_C');Tfile.SETRANGE (Path, 'C:\Users\Administrator\Desktop\Project');
0 -
](*,) it not work ](*,)
I created a new codeunti to a test
the new CODEUNIT named XXXXX,
b]OnRun()[/b]
IF ISCLEAR(Timer) THEN BEGIN
CREATE(Timer);
Timer.Interval := 300000;
Timer.Enabled := TRUE;
END;
Timer::Timer(Milliseconds : Integer)
TFile.reset;
TFile.setrange(Path,'C:\Users\Administrateur\Desktop\PROJET');
TFile.setrange("Is a file",TRUE);
if Tfile.find('-') then
repeat
CODEUNIT.RUN(CODEUNIT::PROJET);
until TFile.next=0;
and i call it from NAS (Codeunit 1 function 99) : CODEUNIT.RUN(CODEUNIT::XXXXX);
](*,)0 -
houssayen wrote:TFile.setrange(Path,'C:\Users\Administrateur\Desktop\PROJET');0
-
the file is in the directory "PROJET" is:
The Path is: C: \ Users \ Administrator \ Desktop \ PROJET
](*,)0 -
may be the problem is at the opening of the file in the codeunit project:
On Run[\b]
InFile.WRITMODE:=FALSE;
InFile.TEXTMODE:=TRUE;
InFile.Open('C:\Users\Administrateur\Desktop\PROJET\B_C);
..............
treatements
..............
is that I remove the instruction of opening the file or not?
if so, what level of code I can put this opening statement??0 -
PLEASE , i need your help.. ](*,)
this is the last task of my project..0 -
Hi
1 - Change your folder to a smaller path, maybe 'C:\Project'.
2 - What of the 2 codeunit you use has SINGLEINSTANCE property set to TRUE ?. Only the first one must have it.
3 - delete IF ISCLEAR.... condition. USe only CLEAR.
4 - Before try it with NAS, run it from object desiggner using debugger and find where the mistake is.
Bye0 -
I use SINGLEINSTANCE property has set to TRUE of
Timer:: Timer (Milliseconds: Integer) In The codeunit XXXXX .. if not there, what level should I change this property??0 -
Hi
It's Ok here
Bye
P.D.: Use Debugger to identify where is the problem0 -
I used the debugger, it posted my:
Timer:: TimerError (errorString)
OnRun ()
-> CLEAR (timer);
CREATE (Timer);
Timer.Interval: = 60000;
Timer.Enabled: = TRUE;
that is to say that the error in the timer !!!!!0 -
Hi
I tried this codeunit and it works. Each minute, i've message for each file in C:\ folderOBJECT Codeunit 50073 Prueba { OBJECT-PROPERTIES { Date=18/05/11; Time=12:07:03; Modified=Yes; Version List=; } PROPERTIES { SingleInstance=Yes; OnRun=BEGIN CLEAR(Timer); CREATE(Timer); Timer.Interval:=60000; Timer.Enabled:=TRUE; END; } CODE { VAR Timer@1000000000 : Automation "{3B311C81-140E-11D5-8B18-00D0590B4EC5} 1.0:{3B311C92-140E-11D5-8B18-00D0590B4EC5}:'Navision Timer 1.0'.Timer" WITHEVENTS; TFile@1000000001 : Record 2000000022; EVENT Timer@1000000000::Timer@1(Milliseconds@1000000000 : Integer); BEGIN TFile.RESET; TFile.SETRANGE(Path,'c:\'); TFile.SETRANGE("Is a file",TRUE); IF TFile.FIND('-') THEN REPEAT MESSAGE(TFile.Name); UNTIL TFile.NEXT=0; END; EVENT Timer@1000000000::TimerError@2(ErrorString@1000000000 : Text[1024]); BEGIN END; BEGIN END. } }
Stupid question. When you change something in your singleinstance codeunit, do you restart Navision ??? If you don't didd it, your modifications not be able until you restart Navision.
Bye
Bye0 -
THANKS, it worked ,
but if i want move the text file after displaying his name, for example I want her to move to a another directory that has as
path: "C: \ resolved " ,
I tried with with these instructions, but it no longer works, it gives me a message blocking ''the table is read-only TFile''..
in the repeat loop,
REPEAT
MESSAGE ('THE NAME OF FILE:% 1 ', Tfile.Name);
Tfile.Path: = 'C: \ RESOLVED';
Tfile.MODIFY;
UNTIL Tfile.NEXT = 0;
it gives me a message blocking ''the table is read-only TFile''.. So how can I do??0 -
FILE.COPY(FromFolder,ToFolder);
0 -
thanks for information, to its not working, how can I change it so that the file moves
from the directory: C \ project to another directory: C: \ RESOLVED
here is the party of codeunit,
REPEAT
MESSAGE ('THE NAME OF FILE:% 1 ', Tfile.Name);
UNTIL Tfile.NEXT = 0;0 -
Hi
Try thisTFile.RESET; TFile.SETRANGE(Path,'c:\Origen'); TFile.SETRANGE("Is a file",TRUE); IF TFile.FIND('-') THEN REPEAT DestinyPath:='c:\Destiny\'+TFile.Name; COPY(TFile.Path+'\'+TFile.Name,DestinyPath); ERASE(TFile.Path+'\'+TFile.Name); UNTIL TFile.NEXT=0;
Bye0
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