SavesAS Function & File Management in Business Central On-Prem (ver16)

xhirvana
Member Posts: 5
I am currently working on a Packing List report that needs to save as pdf automatically in a particular path in our server upon click of an action button in a Sales Order. I am new to development, I have tried following the saveaspdf method in the Microsoft website however when the action button was ticked now, an I/O Error shows even when I already deleted the codes I have done in the Visual Studio Code. Is there any sample code you can advise to achieve the first scenario I have mentioned above? Another twist to this is that, it should only save when the sell-to customer code is equal to Customer 1, Customer 2 & Customer 3...help me please! Will File Management Code Unit help me with this? Thank you in advance!
0
Answers
-
[Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Not sure if it is still needed, but below should give some inspiration.
File Management codeunit is the one you need indeed.
You could also fill up the AllowedCustomers list dynamically, e.g. loop through all customers that have a boolean checked and use the .Add function for them to add their Code to the list.
Just remember that these files will be saved on the server and there is no automatic way to download them to the client. Since we now work through the web browser, we can no longer access the client file system directly.procedure SavePackingList(SalesHeader: Record "Sales Header") var FileMgt: Codeunit "File Management"; ReportToRun: Report "AAA Packing List Report"; JobsSetup: Record "Jobs Setup"; ServerFileName: Text; AllowedCustomers: List of [Code[20]]; begin // Get Setup JobsSetup.Get(); JobsSetup.TestField("AAA Packing List Save Location"); // Check if file needs to be saved AllowedCustomers.Add('CUSTOMER1'); AllowedCustomers.Add('CUSTOMER2'); AllowedCustomers.Add('CUSTOMER3'); if (not AllowedCustomers.Contains(SalesHeader."Sell-to Customer No.")) then exit; // Save file ServerFileName:= JobsSetup."AAA Packing List Save Location" + '\PackingList_' + SalesHeader."No." + '.pdf'; ReportToRun.SetTableView(SalesHeader); ReportToRun.UseRequestPage(false); ReportToRun.SaveAsPdf(ServerFileName); end;
I admit, I did not try the code above, but it should work.
After the report has run, you could also save the created file location to a field on the Sales Header for later use.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions