Report printing through Job scheduler

bksbks Member Posts: 115
Hi,

I am trying to print one report (using Virtual PDF) and mail it to relevant customer.

The code have written in 5961- JobScheduler-Run Object is as below:
OnRun(VAR Rec : Record "Job Scheduler Setup")

CASE "Object Type" OF
  "Object Type"::Report:
   ---- from here---- 
   IF Cust.FINDFIRST THEN REPEAT
      CustG.SETRANGE("No.",Cust."No.");
      CustG.SETRANGE("Date Filter","Start Date","End Date");
      CustG.SETFILTER("E-Mail",'<>%1','');
      IF CustG.FINDFIRST THEN BEGIN
        REPORT.RUNMODAL("Object No.",FALSE,FALSE,CustG);
        Mail.NewMessage(CustG."E-Mail",'','Customer Statement','PFA the customer statement',CustG.Attachment,TRUE);
      END;
    UNTIL Cust.NEXT = 0;
------

Start date and End date are new fields in Job Scheduler Setup table which will give user defined filter.

The problem goes like this-

Cutomer- 1000 has email id as abc@xyz.com and custome - 1001 has email id as abc@pqr.com. For the given date filter- say 010108..020108, there is no record for customer- 1000. So, the code should send e-mail only to customer- 1001 (as there are some records for this customer in given date range).

Right now, my code is generating two mails- for customer 1000 and for customer 1001 and attaches the report for customer 1001 to both the e-mail which is wrong...

Please tell me where I am going wrong and how I should change my code??? ](*,)

Comments

  • ara3nara3n Member Posts: 9,256
    You need to delete the PDF file after each customer is printed, also before calling
    Mail.NewMessage

    You need to check and see if there is a PDF document and if it exists you need to send the email otherwise don't send the email.

    if PDF Exists then
    Delete(PDF FIle)
    REPORT.RUNMODAL("Object No.",FALSE,FALSE,CustG);
    If PDF Exists then do
    Mail.NewMessage
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • bksbks Member Posts: 115
    Hi ara3n, thanks for the reply...

    Can you please tell me what would be "PDF Exist" ? Is it a boolean variable? and how do I check whether it is true or false?
  • DenSterDenSter Member Posts: 8,305
    Off topic, but you are not using the right keywords in your code.

    When you need to loop through a set of records, you should not use FINDFIRST, but FINDSET. FINDFIRST is NOT a simple replacement of FIND('-').
  • ara3nara3n Member Posts: 9,256
    bks wrote:
    Hi ara3n, thanks for the reply...

    Can you please tell me what would be "PDF Exist" ? Is it a boolean variable? and how do I check whether it is true or false?

    well you are storing the pdf somerwhere

    if Exists('C\pdffile.pdf') then
    Delete('C\pdffile.pdf'))
    REPORT.RUNMODAL("Object No.",FALSE,FALSE,CustG);
    if Exists('C\pdffile.pdf') then
    Mail.NewMessage
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.