Use NAS to generate PDF Then attach to an Email

ForeverBlueForeverBlue Member Posts: 54
Hi,

I have create the codeunit to use Bullzip PDF to generate PDF. The function working great, but when I put it in the Job Queue then there is an error message,"You cannot use C/AL variables of type DIALOG when running the Application Server for Microsoft Dynamics NAV Classic."

I have disable any dialog in the report.

In the codeunit, I believed I disable popup window for Bullzip.
BullZipPDF.Init;
BullZipPDF.LoadSettings;
BullZipPDF.SetValue('OutPut', PDFFilePath + PDFFileName);
BullZipPDF.SetValue('Showsettings', 'never');
BullZipPDF.SetValue('ShowSaveAS', 'never');
BullZipPDF.SetValue('ShowPDF', 'no');
BullZipPDF.SetValue('ShowProgress', 'no');
BullZipPDF.SetValue('ShowProgressFinished', 'no');
BullZipPDF.SetValue('SuppressErrors', 'yes');
BullZipPDF.SetValue('ConfirmOverwrite', 'no');
BullZipPDF.WriteSettings(TRUE);

REPORT.RUNMODAL(50007, FALSE, FALSE);
Did I miss anything??
Thanks

Comments

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    This code-extract looks fine to me, but as you didn't publish all code, we can only guess why it gives you that error.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • ForeverBlueForeverBlue Member Posts: 54
    sorry about that.. This is my codeunit
    IF ISCLEAR(BullZipPDF) THEN
      CREATE(BullZipPDF);
    
    PDFFilePath := 'E:\Flash\';
    PDFFileName := 'FlashReport_'+FORMAT(DATE2DMY(TODAY,2))+'_'
                   +FORMAT(DATE2DMY(TODAY,1))+'_'+FORMAT(DATE2DMY(TODAY,3)) + '.pdf';
    
    BullZipPDF.Init;
    BullZipPDF.LoadSettings;
    BullZipPDF.SetValue('OutPut', PDFFilePath + PDFFileName);
    BullZipPDF.SetValue('Showsettings', 'never');
    BullZipPDF.SetValue('ShowSaveAS', 'never');
    BullZipPDF.SetValue('ShowPDF', 'no');
    BullZipPDF.SetValue('ShowProgress', 'no');
    BullZipPDF.SetValue('ShowProgressFinished', 'no');
    BullZipPDF.SetValue('SuppressErrors', 'yes');
    BullZipPDF.SetValue('ConfirmOverwrite', 'no');
    BullZipPDF.WriteSettings(TRUE);
    
    REPORT.RUNMODAL(50007, FALSE, FALSE);
    
    IsDone := FALSE;
    I := 0;
    REPEAT
      IF FILE.EXISTS(PDFFilePath+PDFFileName) THEN BEGIN
        IF testFile.OPEN(PDFFilePath+PDFFileName) THEN BEGIN
          IsDone := TRUE;
        END;
      END;
      I += 1;
      SLEEP(1000);
    UNTIL (I > 60) OR IsDone;
    
    IF IsDone THEN BEGIN
      SenderName := 'Navision';
      SenderAddress := 'support@something.com';
      SendTO := 'someone@something.com';
      Subject := 'Report.';
      Email.CreateMessage(SenderName, SenderAddress, SendTO, Subject, 
        'This is an automatic generated email from Navision.  Please do not reply.', FALSE);
      Email.AddAttachment(PDFFilePath+PDFFileName);
      Email.Send;
    END;
    
  • Alex_ChowAlex_Chow Member Posts: 5,063
    My guess is that the report is bringing up the "Searching for record..." dialog box because the wrong key is used.
  • jspoppjspopp Member Posts: 54
    Hi, is your variable TestFile set to DataType of Dialog? If so, that's probably where you are getting tripped up
  • ForeverBlueForeverBlue Member Posts: 54
    jspopp wrote:
    Hi, is your variable TestFile set to DataType of Dialog? If so, that's probably where you are getting tripped up
    my testFile is File Datatype
  • ForeverBlueForeverBlue Member Posts: 54
    Name	DataType	Subtype	Length
    PDFFilePath	Text		250
    PDFFileName	Text		250
    DefaultPrinter	Text		100
    TempDir	Text		100
    FlashReport	Report	Flash Report	
    IsDone	Boolean		
    I	Integer		
    testFile	File		
    SendTO	Text		1000
    Email	Codeunit	SMTP Mail	
    SenderName	Text		100
    SenderAddress	Text		1024
    Subject	Code		50
    BullZipPDF	Automation	'Bullzip'.PDFPrinterSettings
    
  • ForeverBlueForeverBlue Member Posts: 54
    When I run the Codeunit via Object designer this window pop up
    417201232142pm.png
  • jspoppjspopp Member Posts: 54
    Try commenting these lines out (or removing it from your code) and then run the NAS. See if that fixes the issue
  • ForeverBlueForeverBlue Member Posts: 54
    jspopp wrote:
    Try commenting these lines out (or removing it from your code) and then run the NAS. See if that fixes the issue

    I comment out

    BullZipPDF.SetValue('Showsettings', 'never');
    BullZipPDF.SetValue('ShowSaveAS', 'never');
    BullZipPDF.SetValue('ShowPDF', 'no');
    BullZipPDF.SetValue('ShowProgress', 'no');
    BullZipPDF.SetValue('ShowProgressFinished', 'no');
    BullZipPDF.SetValue('SuppressErrors', 'yes');
    BullZipPDF.SetValue('ConfirmOverwrite', 'no');
    BullZipPDF.WriteSettings(TRUE);

    still no luck...

    I think it's the print progress windows (the screenshot above), but i don't know how to disable that. The ShowProgress and showProgressFinished are already set to no.
  • jspoppjspopp Member Posts: 54
    Try commenting this line out:

    IF testFile.OPEN(PDFFilePath+PDFFileName) THEN BEGIN
  • ForeverBlueForeverBlue Member Posts: 54
    If I comment everything out, still have the same error.... ](*,)
    Wait after I compile the Codeunit, do I have to restart NAS??
  • jspoppjspopp Member Posts: 54
    Yes, restart the NAS and then see what happens after that
  • ForeverBlueForeverBlue Member Posts: 54
    After restart the NAS during down time, I don't have the error anymore :thumbsup: .
    But even in the job Queue Log Entries shows Success, there is not time stamp in the End Date/Time and no PDF was generated and no email send... ](*,) The status of record in Job Queue Entries stays in In Process... AND I can't stop the NAS
  • ForeverBlueForeverBlue Member Posts: 54
    So the problem solved, it's very simple and stupid... :oops:
    I login the server as the user account use by the NAS service then set the BullzipPDF printer as the default printer. Problem solved...
Sign In or Register to comment.