"Client callbacks are not supported" error

AitorEGAitorEG Member Posts: 342
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:
ex5wl2vw5jmc.png
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

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    I guess Mail variable is referencing Codeunit 397.

    Codeunit 397 uses oultlok integration, which runs in user sessions, uses user mail profile, etc. When you run it from Task Scheduler there is no user session.

    Try to used Codeunit 400 SMTP mail instead.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AitorEGAitorEG Member Posts: 342
    edited 2018-05-22
    Thanks for your answer @Slawek_Guzek. I'll work on it, but in the error, it looks that the first failure is with the file maangement. In fact, the PDF is not generated in the folder....

    edit: I've commented the part of sending the e-mail, just for creating the PDF file, and the rror persists, so it looks that the first error is that one.
  • AitorEGAitorEG Member Posts: 342
    Hi @Slawek_Guzek,

    I've changed the code:
    //<<180503-01>>
    IF NOT ISSERVICETIER THEN
      EXIT;
    // IF  GUIALLOWED 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@basemetalurgica.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);
    Mail.CreateNewMessage2(FromMail,ToMail,'',Tofile,EmailHeader,EmailBody,EmailFoot,ServerDestination + Tofile,FALSE);
    

    And now, the error is:
    System.Web.Services.Protocols.SoapException: Microsoft Dynamics NAV Business Web Services attempted to issue a client callback to create a DotNet object: Microsoft.Office.Interop.Outlook.ApplicationClass 
    (CodeUnit 397 Mail). Client callbacks are not supported on Microsoft Dynamics NAV Business Web Services.
       en System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       en System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       en SendOutsOrders.WebService.BasemetaFunc.OutstandingOrderLines() en c:\Users\Administrador\Documents\Visual Studio 2012\Projects\SendOutsOrders\SendOutsOrders\Web 
    References\WebService\Reference.cs:l¡nea 341
       en SendOutsOrders.Program.Main(String[] args) en c:\Users\Administrador\Documents\Visual Studio 2012\Projects\SendOutsOrders\SendOutsOrders\Program.cs:l¡nea 26
    

    This could be becasue of what you'ce said, about he codeUnit 397?

    Thank you very much
  • AitorEGAitorEG Member Posts: 342
    Using the CU400, means that I should configure the SMTP server, am i right??
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2018-05-22
    Yes, you need to setup the SMPT server address/port/authentication.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AitorEGAitorEG Member Posts: 342
    edited 2018-05-23
    Yes, you need to setup the SMPT server address/port/authentication.

    Thank you Slawek. And if I use Job Queues instead of task Scheduler, will it work with CU397? Or I will have the same problem?
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2018-05-23
    Yes, it's gonna to be the same problem. Stick to the C400 SMPT Mail.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AitorEGAitorEG Member Posts: 342
    Yes, it's gonna to be the same problem. Stick to the C400 SMPT Mail.

    Thanks Slawek.
    So, I think that could be a problem, because I will probably want to send e-mails from different mail accounts, depending on the customer. That will be quite easy with CU397, but if I use CU400, I should configure the SMTP server, and that is for the whole company.... Am I right?

    Thank you very much
  • KTA8KTA8 Member Posts: 398
    AitorEG wrote: »
    Yes, it's gonna to be the same problem. Stick to the C400 SMPT Mail.

    Thanks Slawek.
    So, I think that could be a problem, because I will probably want to send e-mails from different mail accounts, depending on the customer. That will be quite easy with CU397, but if I use CU400, I should configure the SMTP server, and that is for the whole company.... Am I right?

    Thank you very much

    the from mail could be anyone authorised by the mail support by the mail you've config.

    I've done it, I've only one config account by I've send by other depends if the department is sales, or purchase, manufacturing, etc.
Sign In or Register to comment.