Hi all!
Our company is still working with the Classic Client and 4.0 database. I've a question about passing data into variables on a request form.
- I have a tabular form which has the table Sales Line as source
- On this form I have a button which sets the filters to the record which is selected on the form and based on this record, it runs runs a report
lRecSalesLine.RESET;
lRecSalesLine.SETVIEW(Rec.GETVIEW);
lRecSalesLine.COPYFILTERS(Rec);
lRecSalesLine.SETRANGE(lRecSalesLine."Line No.", "Line No.");
lRecSalesLine.SETRANGE(lRecSalesLine."Document No.", "Document No.");
lRecSalesLine.SETRANGE(lRecSalesLine."Sell-to Customer No.", "Sell-to Customer No.");
REPORT.RUNMODAL(50008,TRUE,FALSE,lRecSalesLine)
- I want to have a textbox on the request form that, upon running the report, gets the default value from the field "Sales Line".Quantity (the idea is that each sold product gets a label attached on the box, so sold quantity is mostly the amount of prints)
- The reason that I want it in a textbox on the request form, is that I want to be able to change the amount of prints if needed (Some customers want labels on both sides, for example)
- The part that handles the multiple prints works fine already: the problem is that I can't get the value to the request form .
- I've created a Global Variable 'NoOfCopies' of the type integer
- I've created a text box, which property 'SourceExpr' is 'NoOfCopies
- When I click on a blank part of the request form, and click on C/AL code, I get the section 'Report - OnInit()'. In this section I put the code
NoOfCopies := "Sales Line".Quantity;
- When running the report the value of NoOfCopies stays '0'
- If I replace the code with 'NoOfCopies = 3;' the value of NoOfCopies on the request form is 3
Can someone please tell me what I'm doing wrong? I think it is just something small, but I can't figure out, what I'm doing wrong.
Thanks in advance!
Answers
The data item variable is not initialized until OnPreReport trigger - which is long after the request form is open.
I'm afraid you will not be able to use REPORT.RUN / REPORT.RUNMODAL and pass a parameter to be used on RequestForm. Not without using some tricks like using a single instance codeunit and passing parameters through it.
If you always use the same report 50008 for printing your labels, add some functions to it setting up required variables, in calling code declare the report as a report variable, and use the functions to pass parameters
Someting like:
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
The function has one line:
When the function is called from your button, it will know the value you've passed to it.
I've set up a report variable, and this is working now: but now I want to use multiple reports. I've created an If-Then routine to choose between multiple report variables, but can't this be done easier? When calling the function I have a integer parameter with the reportnr., which I want to use, so maybe this can be used?