AL icon indicating copy to clipboard operation
AL copied to clipboard

Help needed - saving files on BC SAAS

Open RHansenEpimatic opened this issue 7 years ago • 4 comments

Not really a bug but wasn't sure where to post this. To migrate a NAV add-on to BC, we need to save documents (reports) as PDF files and then send them out through SMTP mail. We need to specifically name the PDFs (formatted names). On premise this is all easy enough...but how does this work on BC cloud? I think most functions in codeunit 419 are on premise only...correct? Is there a way to use SAVEASPDF on the SAAS version?

RHansenEpimatic avatar Mar 23 '19 15:03 RHansenEpimatic

Nice question I started working on project to pull files in and was looking to save them as we have in past. Not sure we can do on BC unless we save them a link to a container to store them on.

thomasbook avatar Mar 24 '19 14:03 thomasbook

I found a post outlining how to use SAVEAS to save report output to a stream, and to then use that stream as a PDF email attachment, so that should work. I think the only option for pulling files in would be to store them in BLOB fields within the database. Not great for database size, but the file system seems to be off limits in BC SAAS.

RHansenEpimatic avatar Mar 24 '19 14:03 RHansenEpimatic

You can use saves as RHansenEpimatic commented. Something like

    Table.Reset();
    Table.SetRange("No.", DocNo);
    RecRef.GetTable(Table);
    Clear(TmpBlob);
    TmpBlob.Blob.CreateOutStream(outStream1);
    if Report.SaveAs(ReportID, '', ReportFormat::Pdf, outStream1, RecRef) then
        if TmpBlob.Blob.HasValue() then begin
            TmpBlob.Blob.CreateInStream(instream1);
            SMTPMail.CreateMessage(SenderName,Sender,Recipients,Subject, Body, IsHTML);
            SMTPMail.AddAttachmentStream(instream1, AttachmentName);
            SMTPMail.Send();
         end;

tinfister avatar Mar 25 '19 11:03 tinfister

Thanks for sharing what you found might be the only option we have.

thomasbook avatar Mar 26 '19 15:03 thomasbook