Get current record in a loop inside a WITH..DO

poppins
Member Posts: 647
Hi everyone,
This is the code of function SendRecords in table 112 Sales Invoice Header.This code is used when we want to print one or many invoices from the posted invoices list:
LOCAL SendRecords(ShowRequestForm : Boolean;SendAsEmail : Boolean)
WITH SalesInvoiceHeader DO BEGIN
COPY(Rec);
ReportSelections.SETRANGE(Usage,ReportSelections.Usage::"S.Invoice");
ReportSelections.SETFILTER("Report ID",'<>0');
ReportSelections.FIND('-');
REPEAT
IF NOT SendAsEmail THEN
REPORT.RUNMODAL(ReportSelections."Report ID",ShowRequestForm,FALSE,SalesInvoiceHeader)
ELSE
SendReport(ReportSelections."Report ID",SalesInvoiceHeader)
UNTIL ReportSelections.NEXT = 0;
END;
Let's say I selected two records, I want the invoices to be printed separately (get the request page displayed twice, and the records printed one by one).
I tried the following:
WITH SalesInvoiceHeader DO BEGIN
COPY(Rec);
IF FINDSET THEN
REPEAT
ReportSelections.SETRANGE(Usage,ReportSelections.Usage::"S.Invoice");
ReportSelections.SETFILTER("Report ID",'<>0');
ReportSelections.FIND('-');
REPEAT
IF NOT SendAsEmail THEN
REPORT.RUNMODAL(ReportSelections."Report ID",ShowRequestForm,FALSE,SalesInvoiceHeader)
ELSE
SendReport(ReportSelections."Report ID",SalesInvoiceHeader)
UNTIL ReportSelections.NEXT = 0;
UNTIL (NEXT =0);
END;
This way, I got the request page displayed twice, but each time I got the two records printed, not just the current one...
How can I achieve what I described, any ideas?
Thanks in advance
This is the code of function SendRecords in table 112 Sales Invoice Header.This code is used when we want to print one or many invoices from the posted invoices list:
LOCAL SendRecords(ShowRequestForm : Boolean;SendAsEmail : Boolean)
WITH SalesInvoiceHeader DO BEGIN
COPY(Rec);
ReportSelections.SETRANGE(Usage,ReportSelections.Usage::"S.Invoice");
ReportSelections.SETFILTER("Report ID",'<>0');
ReportSelections.FIND('-');
REPEAT
IF NOT SendAsEmail THEN
REPORT.RUNMODAL(ReportSelections."Report ID",ShowRequestForm,FALSE,SalesInvoiceHeader)
ELSE
SendReport(ReportSelections."Report ID",SalesInvoiceHeader)
UNTIL ReportSelections.NEXT = 0;
END;
Let's say I selected two records, I want the invoices to be printed separately (get the request page displayed twice, and the records printed one by one).
I tried the following:
WITH SalesInvoiceHeader DO BEGIN
COPY(Rec);
IF FINDSET THEN
REPEAT
ReportSelections.SETRANGE(Usage,ReportSelections.Usage::"S.Invoice");
ReportSelections.SETFILTER("Report ID",'<>0');
ReportSelections.FIND('-');
REPEAT
IF NOT SendAsEmail THEN
REPORT.RUNMODAL(ReportSelections."Report ID",ShowRequestForm,FALSE,SalesInvoiceHeader)
ELSE
SendReport(ReportSelections."Report ID",SalesInvoiceHeader)
UNTIL ReportSelections.NEXT = 0;
UNTIL (NEXT =0);
END;
This way, I got the request page displayed twice, but each time I got the two records printed, not just the current one...
How can I achieve what I described, any ideas?
Thanks in advance

0
Comments
-
I didn't try it, and there may be better ways to do this, but try it.
Runmodal doesnt care which Record (invoice) you currently hold, its all about the filter.WITH SalesInvoiceHeader DO BEGIN COPY(Rec); IF FINDSET THEN REPEAT ReportSelections.SETRANGE(Usage,ReportSelections.Usage::"S.Invoice"); ReportSelections.SETFILTER("Report ID",'<>0'); ReportSelections.FIND('-'); REPEAT IF NOT SendAsEmail THEN BEGIN //new variable and code SalesInvHeader2.RESET; SalesInvHeader2.COPYFILTERS(SalesInvoiceHeader); SalesInvHeader2.SETRANGE("no.",SalesInvoiceHeader."No."); //--- REPORT.RUNMODAL(ReportSelections."Report ID",ShowRequestForm,FALSE,SalesInvHeader2) //InvHeader2 here ELSE SendReport(ReportSelections."Report ID",SalesInvoiceHeader) UNTIL ReportSelections.NEXT = 0; UNTIL (NEXT =0); END;
Austrian NAV/BC Dev0
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