Hi everyone,
First of all, I’m gonna explain my intentios of doing this development, may be I am a bit confused, and I can do it in another way that doesn’t launch this error.
My idea is to periodically send an email with an attached PDF to different customers. This is an approach to the developmet.
First of all, I run this method in a CodeUnit:
OutstandingOrderLines()
lCustomer.RESET;
lCustomer.SETRANGE("Send Outstanding Orders", TRUE);
IF lCustomer.FINDSET THEN
REPEAT
SendOutstanding2Customer(lCustomer, 50074);
UNTIL lCustomer.NEXT=0;
And this method, calls to this one:
SendOutstanding2Customer(VAR pCustomer : Record Customer;ReportID : Integer)
IF NOT ISSERVICETIER THEN
EXIT;
CLEAR(ToMail);
CLEAR(FromMail);
CLEAR(EmailHeader);
CLEAR(EmailBody);
CLEAR(EmailFoot);
CLEAR(Mail);
CLEAR(ServerDestination);
CLEAR(ClientDestination);
CLEAR(Customer);
PurchSetup.GET;
EmailHeader := PurchSetup."eMail Header for Sales Info";
EmailFoot := PurchSetup."eMail Foot for Sales Info";
EmailBody := '';
ToMail := pCustomer."E-Mail";
FromMail := 'info@xxxxxx.com';
ServerDestination := 'C:\Users\Public\Documents\';
Tofile := STRSUBSTNO('Outstanding orders %1,%2.pdf', FORMAT(TODAY,0,'<Year,2><Day,2><Month,2>'), pCustomer.Name);
REPORT.SAVEASPDF(ReportID,ServerDestination + Tofile,pCustomer);
//REPORT.SAVEASEXCEL(ReportID,ServerDestination + Tofile);
ClientDestination := 'C:\Users\Public\Documents\';
FileManagement.DownloadToFile(ServerDestination + Tofile,ClientDestination + Tofile);
Mail.CreateNewMessage2(FromMail,ToMail,'',Tofile,EmailHeader,EmailBody,EmailFoot,ClientDestination + Tofile,FALSE);
As you can see, I find some customer, and I send a report to each of them. First of all, I create the PDF file in a folder, and afterm I attach it to the email.
This works perfectly when I run the codeUnit, but as I want to send the mails periodically, I must to use the “Task Scheduler”. For this, I have created an script that calls to the method in the CodeUnit, but when I run the script, I can see this error:
I’ve read in different places, that could be somethin with the “GUIALLOWED” property, but I don’t see how should I fix this issue.
Any hint?
Thank you vey much