HAL to save an attached file to client
Paul Timms
10-10-19
I am struggling to write HAL code which simply takes an attach file from a record and saves it onto the client. The issue appears to be related to the size of the attach file, since below a certain size, my code works correctly.

The code to find the attach file runs on the server, and works fine. The only way I have found to save that file to the client is to run AddAttachFileToArea, then use ClientRemoteAsync.ClientProcedure(filename,area), which runs WriteAreaToFile. The issue is that if the area is above a certain size (somewhere between 300kb and 390kb) the procedure does not run at all.

I have tried sending the Attach2Vc to the client procedure and then using AddAttachFileToArea but this creates a zero byte file on the client.

I then tried, from the client procedure, a remote call to another procedure which does AddAttachFileToArea with a variable area feeding back to the client procedure. This has the same problem as originally, i.e. it only works if the area is below a specific size.

Without ClientRemoteAsync the functions WriteAreaToFile, OutAreaToFile, LogAreaToFile and AppendAreaToFile all write the file to the server.

Does anyone have any ideas? Maybe there's a different way to achieve this?
Edgars Dzenis
12-11-19
Hello,

You can try working with DownloadAttachedFile
Paul Timms
12-18-19
Hi Edgars

Do you have any information about this primitive? It is missing from the HAL Primitives website. I can only find one use of it in HAL source, and it's not exactly clear how it works. For example, where does it download the attached file to?

Thanks

Paul
David Delač
12-19-19
Hello Paul,

Please repeat these steps to understand behaviour:

1. Create Invoice and fill it up as you would normally do it
2. Attach "test.pdf" to it
3. Create .hal file with code below and add it to halcust
NOTE: Replace IVr.SerNr = 10000007; with serial number of the invoice you just created
4. Make sure It's compiled by restarting and then navigate to Technics >> Reports >> Empty Report and run it

There are 2 possible outcomes:
• File will be opened and shown to user
• Save window will open and provide you with ability to save file on your machine

This depends on the second argument. If FALSE user will get option to save file somewhere on his machine and if TRUE file will be opened.



event startup
begin
SetLangMode(LangEnglish,"ENG",0);
Report("Empty Report",EmptyRClass,EmptyRn,0,modTC);
end;


event DefineWindows
begin
real x,h,h1,h2,h3,h4,h5,h6,h7,v,v2,l,vs,vm,f,t;

SetLangMode(LangEnglish,"ENG",0);
WindowBegin("Specify My Own Report ",EmptyRClass,CGRcW,RcType);
SetWRect(5,73,415,250);
v = 6; vs = 20; h = 120;
EndWindow;

end;

global
procedure EmptyRn(record RcVc RepSpec)
begin
Integer filenr;
record IVVc IVr;
record RLinkVc RLr;
record Attach2Vc Attach2r;
string 255 filename;
Boolean res;

StartReportJob("Empty Report");
EndHeader

IVr.SerNr = 10000007;
if (ReadFirstMain(IVr,1,true)) then begin
filename = "test.pdf";
filenr = 1;
while (ReadRecordLink(IVr,filenr,Attach2r,RLr)) begin
if (Attach2r.FileName==filename) then begin

res = true;
goto LExit;
end;
filenr = filenr + 1;
end;
end;
LExit:;

if (res) then begin
DownloadAttachedFile(Attach2r,false);
end;


EndJob;
return;
end;
Paul Timms
12-19-19
Hi David

Thanks for such an informative reply. I may be able to use it, however the ideal solution would be for the client to download the file to a specified folder, without user intervention and without the file being opened.

Are you able to confirm if there is an area size limit when running code on the client?

Thanks

Paul
David Delač
12-19-19
Hi Paul,

We currently do not have primitive function that is able to achieve that.


Area size limit depends on how it is used. If used in client <-> server then area size supported will be much smaller then if area has been built locally and written to file but unfortunately I don't have exact numbers.

Best Regards,
David D.
HansaWorld Support
Paul Timms
3-9-20
I notice there's a new primitive AddAttachFileToArea2, which accepts an extra boolean compared to AddAttachFileToArea. What is the difference between them?
Piotr Resiak
3-9-20
Hello. Thank You for posting. We will get back to you with the answer shortly.
Edgars Dzenis
3-9-20
Looks like it allows adding file without automatic newline symbol.
The 2nd to last parameter controls that - false: no newline, true: same as AddAttachFileToArea
Paul Timms
3-9-20
Thanks, so just to be clear, one of the booleans controls whether to encode the data in the file, and the other controls whether to add a newline symbol? And how is that the same as AddAttachFileToArea, which only has one boolean parameter?
Edgars Dzenis
3-9-20
For AddAttachFileToArea parameters are: file,area,encoding
For AddAttachFileToArea2 parameters are: file,area,newline,encoding

For AddAttachFileToArea newline parameter is true by default, in AddAttachFileToArea2 it's possible to pass false.

Hope this helps
Paul Timms
3-9-20
Thanks Edgars. Useful to know, but doesn't solve my original problem. I've found that the size limit for passing an area from server to client is somewhere between 301kb and 318kb.
Piotr Resiak
3-9-20
Hello Paul. We will update from our side if anything new.
Paul Timms
3-10-20
We have solved this problem by outputting the attachment to file on the server, then using the primitive DownloadFile to get the file onto the client. It is listed on the HAL Primitives site as "Not used any more" but hopefully it will remain available in future versions.
Piotr Resiak
3-10-20
Hello Paul. Thank You for Your feedback. We will keep You updated.
Gastón Salomone
3-13-20
Hi Piotr,

Please, can you please write an example of the parameters of that function ?

I dind´t find and example on hal source.

Regards
Piotr Resiak
3-13-20
Hello Gastón,
please let me pass Your question to one of our HAL Specialists who will shortly come back to You with a reply in this thread.

Regards,
Paul Timms
3-13-20
Gaston, below is the syntax for downloading a file from a Linux server to a Windows client, where the Attach record has been saved into the tmp folder on the server.

DownloadFile("tmp/" & Attachr.FileName,"tmp\\" & Attachr.FileName, true);

Regards

Paul
Piotr Resiak
3-13-20
Hello Paul, thank You for Your reply which fully covers the topic :)
Dear Gastón, please feel free to ask additional questions if more answers needed.
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
David Delač
Hi Piotr, The log entry:
2024-12-14 08:40:43 0.000 CallHal(IsHansaWorldCustomer) appears because the server is running with the verbosity=debug-detailed setting in its parameters.txt file. Thi...
09:43 16 Dec 2024
Brittany McGrath
Hi Vaughn, I can confirm this has been fixed now and is live in Standard ERP 2024-11-20 Version: 85556786. Thank you. ...
10:04 10 Dec 2024