web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

TWO QUERIES NEEDED ON SAME TABLE

(0) ShareShare
ReportReport
Posted on by

I have a report that I need to find all Sales Invoices Posted during a date range.  From those records I need to find the oldest sales invoice for the job number listed in the posting range to grab the original installer for the job.  Can I have the Sales Invoice Table defined as a dataset, sorted by the posting date, to grab the posting date range records, then define the Sales Invoice table again as a global variable(SIOrig), setting the currentkey as posting date and filter on the job number?  It should grab the first occurrence of the job number in post date order?  And is the posting date order by default ascending or descending?  This would determine whether I used the findfirst or findlast correct?  Something like this?

Sales Invoice - afterrecord()

SIOrig.SETCURRENTKEY(SIOrig."Posting Date");         **SIOrig being second Sales Invoice 

SIOrig.SETFILTER(SIOrig."Job No.","Sales Invoice Header"."Job No.");      defined in global variables
SIOrig.FINDFIRST();
ORIGINALINSTALLER := SIOrig."Head Installer";
ORIGINALINSTALLERNAME := SIOrig."Head Installer Name";

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    what you are trying to do seems logical to me. The only thing I would suggest is using a different key. I would prefer having a key with the Job No. and the posting date in it. If not, your report might be very slow in an operational database.

    kr,

    Francis

  • Community Member Profile Picture
    on at

    it is finding the right record Francis but when I go to insert the head installer from the secondary sales invoice table it will not print.  How do I get it to print?  Create a tempfile insert the sales invoice table and then overlay the head installer from the secondary instance of SI using modify and then print the tempfile

  • Community Member Profile Picture
    on at

    Hi Kim,

    If I understand well, you want to print the ORIGINALINSTALLER and the ORIGINALINSTALLERNAME ?

    In the global variable declaration, you can call the properties (shift+F4). One of the properties is IncludeinDataset. If you set this to Yes, the variable will be available in your report.

    Francis

  • Community Member Profile Picture
    on at

    Francis,

    I used your suggestion and it still did not work.  I stepped through the debugger and I can see that the field contains the information it should however it is not coming out on the report.

  • Suggested answer
    Rakesh Ranjan Profile Picture
    55 on at

    You can use two different dataset with indentation to other ,and it will work as per requirment.

  • Verified answer
    Community Member Profile Picture
    on at

    The report is now working fine I had the SIOrig fields located at the bottom of the dataset and they would not print, moved them up under the Sales Invoice Header dataset and they printed fine.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans