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
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
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
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?
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('-').
RIS Plus, LLC
well you are storing the pdf somerwhere
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n