ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

New parameter on OnBeforeSaveReportAsPDF in Table 77

Open mfalk118 opened this issue 7 years ago • 14 comments

Please add TempBlob to the publisher, so we can actually handle the event. Please also add File Extensions, since we then can manage completely how the files are added. You can write the code like (in BC14):

//OLD OnBeforeSaveReportAsPDF(ReportID,RecordVariant,LayoutCode,IsHandled);

//>>NEW OnBeforeSaveReportAsPDF(ReportID,RecordVariant,LayoutCode,TempBLOB,FileExtension,IsHandled); IF IsHandled THEN BEGIN IF FileManagement.GetExtension(FilePath) <> FileExtension THEN FilePath := FileManagement.GetFileNameWithoutExtension(FilePath) + '.' + FileExtension;

TempBLOB.Blob.CREATEINSTREAM(StreamIn); f.CREATE(FilePath); f.CREATEOUTSTREAM(StreamOut); COPYSTREAM(StreamOut,StreamIn); f.CLOSE; END; //<<NEW

I know it previously has been requested to get the filename as a parameter and it was rejected due to security, but with the above i do not see any reason not to implement it.

Other requets: https://github.com/Microsoft/ALAppExtensions/issues/2213 https://github.com/Microsoft/ALAppExtensions/issues/1394

mfalk118 avatar Oct 02 '19 15:10 mfalk118

Here is current code, you suggestion use variables which does not exist here. Please update you suggestion or close it.

local procedure SaveReportAsPDF(ReportID: Integer; RecordVariant: Variant; LayoutCode: Code[20]) FilePath: Text[250] var ReportLayoutSelection: Record "Report Layout Selection"; FileMgt: Codeunit "File Management"; IsHandled: Boolean; begin OnBeforeSetReportLayout(RecordVariant); FilePath := CopyStr(FileMgt.ServerTempFileName('pdf'), 1, 250);

    ReportLayoutSelection.SetTempLayoutSelected(LayoutCode);
    OnBeforeSaveReportAsPDF(ReportID, RecordVariant, LayoutCode, IsHandled);
    if not IsHandled then
        REPORT.SaveAsPdf(ReportID, FilePath, RecordVariant);
    ReportLayoutSelection.SetTempLayoutSelected('');

    Commit;
end;

AlexanderYakunin avatar Oct 29 '19 09:10 AlexanderYakunin

The variablers should be pretty obvious but here they are:

Vars: Name DataType Subtype Length TempBLOB Record TempBlob StreamOut OutStream StreamIn InStream f File FileExtension Text

LOCAL SaveReportAsPDF(ReportID : Integer;RecordVariant : Variant;LayoutCode : Code[20]) FilePath : Text[250] OnBeforeSetReportLayout(RecordVariant); FilePath := COPYSTR(FileMgt.ServerTempFileName('pdf'),1,250);

ReportLayoutSelection.SetTempLayoutSelected(LayoutCode); OnBeforeSaveReportAsPDF(ReportID,RecordVariant,LayoutCode,IsHandled);

//>>NEW OnBeforeSaveReportAsPDF(ReportID,RecordVariant,LayoutCode,TempBLOB,FileExtension,IsHandled); IF IsHandled THEN BEGIN IF FileManagement.GetExtension(FilePath) <> FileExtension THEN FilePath := FileManagement.GetFileNameWithoutExtension(FilePath) + '.' + FileExtension;

TempBLOB.Blob.CREATEINSTREAM(StreamIn); f.CREATE(FilePath); f.CREATEOUTSTREAM(StreamOut); COPYSTREAM(StreamOut,StreamIn); f.CLOSE; END; //<<NEW IF NOT IsHandled THEN REPORT.SAVEASPDF(ReportID,FilePath,RecordVariant); ReportLayoutSelection.SetTempLayoutSelected('');

mfalk118 avatar Oct 29 '19 09:10 mfalk118

Seems this is code for 14.X which we don't use anymore. And this is not event request, but ask for refactoring of our code? I can forward this ask to another team who is more prepared to review it.

@JesperSchulz - can you have a look to this ask?

AlexanderYakunin avatar Oct 29 '19 09:10 AlexanderYakunin

Well it is a request for actually making the event useable. The code can be more or less copy pasted to AL with a few extra colons for the variables :-)

mfalk118 avatar Oct 29 '19 09:10 mfalk118

Please be aware that you assumption about copy/paste is not correct. We don't have TempBlob table in 15.X and need to use SystemApp interface instead.

AlexanderYakunin avatar Oct 29 '19 09:10 AlexanderYakunin

OK point taken, anyways i would like this in 14 too :-)

mfalk118 avatar Oct 29 '19 09:10 mfalk118

We'll take a look :-) I cannot promise we accept it, but I'll have someone look into if this is something we can move forward with.

JesperSchulz avatar Nov 13 '19 13:11 JesperSchulz

Hi @mfalk118, we had a discussion and this is unfortunately not something we would move forward with due to security reasons. The reason is similar to why the previous issues were rejected as well. In this case, we would be provided with a blob or stream and writing it to a file which we will not support.

-Darrick

darjoo avatar Dec 03 '19 11:12 darjoo

So are you thenh removing the Event Publisher, since it is impossible to "handle" it anyways?

I cannot see what security reasons can be the problem here? Can you elaborate on that?

Please suggest a way we then can intercept the generation of the PDF, and f.ex replace it with an Excel file instead? Or call a webservice where we add a background PDF?

mfalk118 avatar Dec 03 '19 11:12 mfalk118

I will not be removing the event publisher. From the looks of the request issue when the event was added, it seems like the requested event and the actual event in the code is different. I do not know the reasoning for this.

The security issue here is the handling of files, even if they're temporary. The files stored on our servers could be malicious and from the security team's point of view, they're not allowing us to store these files.

Could you elaborate on flow and what you are trying to achieve here?

darjoo avatar Dec 04 '19 15:12 darjoo

If you are extending the publisher with the TempBLOB we are not directly storing files on the server, but OK maybe they are stored later, but then the code should keep it i memory or a safe place. I am trying to extend the email feature with 2 things:

  1. Append background to the Documents (Company logo header and footer)
  2. In some situations attach excel file instead of pdf

I do not want to have the current publisher removed either, however it is impossible to "handle" it now. Only thing that will happen if you subscribe to it and set handled to true, is that no file will be attached to the email. That would be very rare that you actually want that ;-)

mfalk118 avatar Dec 10 '19 13:12 mfalk118

Yes, that is the preferred way we would like it as well. Where the TempBLOB or data is only stored in memory/safe place. Unfortunately there isn't a way to add it directly through TempBLOB or a stream in this scenario. The code flow goes into a DotNet (Not created by us in BC) which only accepts a filepath when it comes to attachments.

I'll revisit it and see if there're any workarounds I can find, but I cannot promise anything.

darjoo avatar Dec 10 '19 14:12 darjoo

We have exactly the same problem.

Our process is as follows: We start an XML port from a report. The data is then sent to a web service. As a result we get a PDF back.

At the moment we cannot use this PDF any further. Therefore we absolutely need a return parameter, like the TempBlob, where we can write back the PDF.

Daniamstutz avatar Dec 11 '19 14:12 Daniamstutz

Also need to manipulate PDF

philip247 avatar Nov 17 '20 08:11 philip247