Navision developper

houssayen
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 ..
«1

Comments

  • kriki
    kriki Member, Moderator Posts: 9,121
    [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!


  • mohana_cse06
    mohana_cse06 Member Posts: 5,506
    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);
    
  • houssayen
    houssayen Member Posts: 45
    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"?
  • mohana_cse06
    mohana_cse06 Member Posts: 5,506
    Create Files Names in your directory as
    test010111.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.
  • houssayen
    houssayen Member Posts: 45
    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..
  • mohana_cse06
    mohana_cse06 Member Posts: 5,506
    What is your file name at C: \ Users \ Administrator \ Desktop?
  • houssayen
    houssayen Member Posts: 45
    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..;)
  • Saalek
    Saalek Member Posts: 181
    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

    Bye
  • houssayen
    houssayen Member Posts: 45
    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?? : (
  • Saalek
    Saalek Member Posts: 181
    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).

    Bye
  • houssayen
    houssayen Member Posts: 45
    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..:(
  • Saalek
    Saalek Member Posts: 181
    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;

    Bye
  • houssayen
    houssayen Member Posts: 45
    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..
  • Saalek
    Saalek Member Posts: 181
    Hi

    This Line is TIMER automation's event.
    Go to Timer variable PROPERTIES and change WITH EVENTS properti to YES.
    This line will appear.

    Bye
  • houssayen
    houssayen Member Posts: 45
    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 ..
  • mohana_cse06
    mohana_cse06 Member Posts: 5,506
    houssayen wrote:
    My directory named PROJECT, He Is in my desktop,
    Tfile.SETRANGE (Path, 'C: \ Users \ Administrator \ Desktop \ DRAFT \ B_C');
    it should be
    Tfile.SETRANGE (Path, 'C:\Users\Administrator\Desktop\Project');
    
  • houssayen
    houssayen Member Posts: 45
    ](*,) 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);

    ](*,)
  • mohana_cse06
    mohana_cse06 Member Posts: 5,506
    houssayen wrote:
    TFile.setrange(Path,'C:\Users\Administrateur\Desktop\PROJET');
    Is Project spelling correct in your path? :-k
  • houssayen
    houssayen Member Posts: 45
    the file is in the directory "PROJET" is:
    The Path is: C: \ Users \ Administrator \ Desktop \ PROJET
    ](*,)
  • houssayen
    houssayen Member Posts: 45
    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??
  • houssayen
    houssayen Member Posts: 45
    PLEASE , i need your help.. ](*,)

    this is the last task of my project..
  • Saalek
    Saalek Member Posts: 181
    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.


    Bye
  • houssayen
    houssayen Member Posts: 45
    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??
  • Saalek
    Saalek Member Posts: 181
    Hi

    It's Ok here

    Bye

    P.D.: Use Debugger to identify where is the problem
  • houssayen
    houssayen Member Posts: 45
    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 !!!!!
  • Saalek
    Saalek Member Posts: 181
    Hi

    I tried this codeunit and it works. Each minute, i've message for each file in C:\ folder
    OBJECT 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

    Bye
  • houssayen
    houssayen Member Posts: 45
    edited 2011-05-18
    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??
  • houssayen
    houssayen Member Posts: 45
    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;
  • Saalek
    Saalek Member Posts: 181
    Hi

    Try this
    TFile.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;
    

    Bye