Passing variables to request form of report

danielbouwmeester
Member Posts: 22
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.
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!
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!
"Make it idiot-proof and someone will invent a better idiot..."
0
Best Answers
-
At the time when the request form is open the "Sales Line" is not initialized yet.
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:... RecSalesLine.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."); CLEAR(Report50005); Report50005.SetParams(lRecSalesLine.Quantity); Report50005.SETTABLEVIEW(lRecSalesLine.getview); Report50005.USEREQUESTFORM(TRUE); Report50005.RUNMODAL.
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035 -
Just in case, if Slawek's suggestion isn't clear, you create a function SetParams. This function has one parameter. I'll call it "NumOfCopiesParameter":
The function has one line:NoOfCopies := NumOfCopiesParameter;
When the function is called from your button, it will know the value you've passed to it.
Ron5
Answers
-
At the time when the request form is open the "Sales Line" is not initialized yet.
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:... RecSalesLine.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."); CLEAR(Report50005); Report50005.SetParams(lRecSalesLine.Quantity); Report50005.SETTABLEVIEW(lRecSalesLine.getview); Report50005.USEREQUESTFORM(TRUE); Report50005.RUNMODAL.
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035 -
Just in case, if Slawek's suggestion isn't clear, you create a function SetParams. This function has one parameter. I'll call it "NumOfCopiesParameter":
The function has one line:NoOfCopies := NumOfCopiesParameter;
When the function is called from your button, it will know the value you've passed to it.
Ron5 -
Thanks very much, both of you: it's working now! I've created both a 'set'-function and a 'get'-function. I've another question:
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?IF recLabelLayoutJVDO.ReportID = 50008 THEN BEGIN CLEAR(report50008); report50008.SETTABLEVIEW(lRecSalesLine); report50008.USEREQUESTFORM(TRUE); report50008.RUNMODAL; END ELSE IF recLabelLayoutJVDO.ReportID = 50009 THEN BEGIN CLEAR(report50009); report50009.SETTABLEVIEW(lRecSalesLine); report50009.USEREQUESTFORM(TRUE); report50009.RUNMODAL; END ELSE IF recLabelLayoutJVDO.ReportID = 50010 THEN BEGIN CLEAR(report50010); report50010.SETTABLEVIEW(lRecSalesLine); report50010.USEREQUESTFORM(TRUE); report50010.RUNMODAL; END ELSE IF recLabelLayoutJVDO.ReportID = 50011 THEN BEGIN CLEAR(report50011); report50011.SETTABLEVIEW(lRecSalesLine); report50011.USEREQUESTFORM(TRUE); report50011.RUNMODAL; END ELSE IF recLabelLayoutJVDO.ReportID = 50088 THEN BEGIN CLEAR(report50088); report50088.SETTABLEVIEW(lRecSalesLine); report50088.USEREQUESTFORM(TRUE); report50088.RUNMODAL; END ELSE ERROR(textNoLabel);
"Make it idiot-proof and someone will invent a better idiot..."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