Need to produce 2 files where 1 files reads the other

engsiong75engsiong75 Member Posts: 143
Hi

I have a customization that print a report in pdf and saves it to a folder . This program is working fine. I tried to modify the report so that the pdf file is first produced and then it is read by a second program and a text file is created in the same folder.

The problem is that I cannot get the pdf file to be printed within the same report as the one trying to access the pdf file. The pdf file is only produced after the program is completed.
1) I have tried using commit statements.
2) I tried to get other reports or codeunits to fire but they do not work.

The only way I could get it to work was when the debugger was on.

Any suggestions?

Tan Eng Siong

Comments

  • RawHeatRawHeat Member Posts: 63
    how do u read data from the pdf file???
  • engsiong75engsiong75 Member Posts: 143
    I am using an API to handle that.
  • engsiong75engsiong75 Member Posts: 143
    Sorry. Let me clarify. The logic to produce the pdf file into a folder is using an API. The logic is read the pdf file is using a third party tool.
  • SogSog Member Posts: 1,023
    you could make a loop that refreshes the folder where the pdf is stored and let it loop until the files has been found (or a timeout of x) and when the file is found you can do your magic.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • BeliasBelias Member Posts: 2,998
    You can also try SLEEP(3000) to wait three secs in order to let the system create the file...
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • matttraxmatttrax Member Posts: 2,309
    Yeah, it's usually not that the program has to end for the file to be created, it's just that there's a delay. Typically only a few seconds. Using the debugger and stepping through the code probably took at least that many seconds, so it looked like the debugger made it work.

    As Belias suggested, I would try using the SLEEP command. Look into EXISTS as well. You can look for the file, if you don't find it sleep for a few seconds, then look again. If you can't find it after a few attempts then throw an error.
  • engsiong75engsiong75 Member Posts: 143
    The SLEEP(3000) does not work if I am trying to get the report to produce the pdf file and then trying to read it in the same report. I tried SLEEP(30000) but it also does not work. Any other better ideas? I also tried it with commit statements but it does not execute.
  • BeliasBelias Member Posts: 2,998
    did you try to put your code in Onpostreport trigger? (i think so)
    also, if you run the report modally, try to run it "non -modally" instead (report.run instead of report.runmodal)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • matttraxmatttrax Member Posts: 2,309
    The actual saving of the file is not up to Navision. That's Windows code and whatever thread needs to execute for the file system to recognize the new file is probably not running.

    Belias' runmodal v. run idea is a good one. RUNMODAL should technically hog the CPU and not let anything else happen until it is done. By using RUN instead (if you're not) it should allow the OS to schedule the threads and the previous ideas like SLEEP should work.

    I know that it is possible to create a file and then do something with it in the same report as I have PDFd reports and attached them to emails many times.
  • BeliasBelias Member Posts: 2,998
    "b" option: (if applicable)
    wrap your report and your "3d party function" in a codeunit, and then run them sequentially

    OnRun()
    Report.runmodal(blahblah); //this is ok because, you can let the report finish
    mythirdparty.mybrilliantfunction(myshiningpdffilepath);
    
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • engsiong75engsiong75 Member Posts: 143
    >>did you try to put your code in Onpostreport trigger? (i think so)
    Yes, I did.

    >>Report.runmodal(blahblah); //this is ok because, you can let the report finish
    You mean instead of launching the report from the report from itself, you want me to launch it from a codeunit?

    I also have seen a feature that creates the pdf file and then attachs it to email. I will check if the developer what was done.
  • BeliasBelias Member Posts: 2,998
    engsiong75 wrote:
    You mean instead of launching the report from the report from itself, you want me to launch it from a codeunit?
    Yes!
    engsiong75 wrote:
    I also have seen a feature that creates the pdf file and then attachs it to email. I will check if the developer what was done.
    I don't know what you want to do...if you want to send a pdf, you can use the method i just said!
    1. run report on a pdf printer
    2. attach the saved pdf to a mail
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.