output report to pdf and attach to mail
Aldevinas Katkus
5-7-21
Operating system: Windows
I would like to attach a report when I create an email from the sales invoice.
So I modified CreateMailFromIVD()
and added a code to generate a PDF report, but it works strange:


In single user mode it attaches only my report PDF to the mail (it should attach an invoice and my report pdfs), even though I can see both PDFs are created in the tmp directory.

In client server mode it crashes the server and does not attach anything.
What is the proper way to create and attach report (not document) to the record?

windows client, linux server

My code:
...
RecordClear(RepSpec);
RepSpec.repname = "MyRn";
ReportDefaults(RepSpec,"MyRClass");
...
SetDocumentFileName(fname);

RepSpec.Media = mtPdf;
SetMedia(mtPdf);
//RunReport(RepSpec,0);
MyRn(RepSpec);//tried to call report instead of RunReport, same result
SetDocumentFilename("");
if (FileExists(fname)) then begin
RecordLinkFile(fname,0,Mailr,CurrentCompany);
Delete_File(fname);

SetDocumentFilename("");
end;

hansa.log
2021-05-06 18:28:47 (1) AK Printing Faktūros 20210111
2021-05-06 18:28:47 (1) AK PDF Error: 4133
...

2021-05-06 18:28:47 (1) AK PDF Error: 4133

2021-05-06 18:28:47 (1) AK backtrace called due to: CopyDVP with some KeyMasterArrType touchedf!=false
2021-05-06 18:28:47 (1) AK -------------------- backtrace start -------------------------
2021-05-06 18:28:47 (1) AK 0: /home/stabilus/ss/StandardERPServer64() [0x6a4838]
...
2021-05-06 18:28:47 (1) AK 22: /home/stabilus/ss/StandardERPServer64() [0x40a942]
2021-05-06 18:28:47 (1) AK 23: /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f3eb669db35]
2021-05-06 18:28:47 (1) AK 24: /home/stabilus/ss/StandardERPServer64() [0x40a9e1]
2021-05-06 18:28:47 (1) AK --------------------- backtrace end --------------------------
2021-05-06 18:28:47 (1) AK
2021-05-06 18:28:47 (1) AK dump of call stack
2021-05-06 18:28:47 (1) AK Exiting to protect the database



David Delač
5-11-21
Hi Aldevinas,

Please refer to code in hal/Tools/IPVcWActionTool3.hal starting on line 1550.

Let me know if this helped.


Best Regards,
David Delač
Aldevinas Katkus
5-12-21
Yes. It works, though I had to comment out a string which contained national characters like this, otherwise the was left in tmp folder and not attached.
fname = "tmp/" /*& USetStr(1818) & " " */ & IPr.SerNr & ".pdf";

Aldevinas Katkus
5-12-21
P.S. Those national characters used in the filename do not look correct, looks like a wrong character encoding was used. Not sure why it happens only when I use hal and works fine in standard.
David Delač
5-18-21
Hi Aldevinas,

Sounds like a bug. Please report it and attach HAL files as well as backup so that we can have a look.

Can I help you with anything else?

Best Regards,
David Delač
Aldevinas Katkus
5-19-21
I guess this should happen with other languages having non ansi charset, because setting the language to ENG, solves the problem.

//Set to English, otherwise fname does not match the file in the filesystem, see gaPDFEmailFiles output in the log if we set language to LIT
SetLangMode(LangEnglish,"ENG",2);
PrintDocument(IVr,docname,false);

LogText(0,"gaPDFEmailFiles=" & gaPDFEmailFiles);
if (FormLinkDocumentFilenames(Mailr,gaPDFEmailFiles)) then begin
RecordCopy(oldIVr,IVr);

IVr.Prntdf = 1;
RecordUpdate(oldIVr,IVr,false);
end;
SetDocumentFilename("");
gPDFEmailf = false;


SetLangMode(LangLithuanian,"LIT",2); //Reset back to local language
Aldevinas Katkus
5-19-21
Reported a bug HAL>>PrintDocument() creates PDF files with incorrect chars
Leave Comment
You can subscribe to notifications for this post by selecting the 'star' icon on the top right corner of the post.
Back to the list
Latest Posts
Andis Blicāns, Grasko
Hi, We have client using 8.5 2021-09-26 (build 85400383). The fields "Max Web Users" and "Max Sessions" ar blank. Server is closing itself almost every day. Message in hansa....
15:52 26 Apr 2024
Afternoon, Some of our customers haven't changed their passwords for a while but they're not getting any password expiry message. If I copy their Standard ID into a new user on some test ...
17:22 25 Apr 2024