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

poppinspoppins 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 :smile:

Comments

  • Wisa123Wisa123 Member Posts: 308
    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 Dev
Sign In or Register to comment.