Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

GET LAST 3 INVOICE WITH ITEMS OF AN ACCOUNT

(0) ShareShare
ReportReport
Posted on by

Dear All,

Need help to generate following View. Im having 2 entity InvoiceHeader, InvoiceHeaderline

Details As below:

Invoice Header InvoiceHeaderLine VIEW REQUIRED
InvoiceNo Invoicedate InvoiceNo ItemNo Amount InvoiceNo Invoicedate ItemNo Amount
Inv1 01-01-2019 Inv1 Item1 100 Inv2 02-01-2019 Item1 100
Inv2 02-01-2019 Inv1 Item2 100 Inv3 03-01-2019 Item1 100
Inv3 03-01-2019 Inv2 Item1 100 Inv3 03-01-2019 Item2 100
Inv4 04-01-2019 Inv3 Item1 100 Inv3 03-01-2019 Item3 100
Inv3 Item2 100 Inv4 04-01-2019 Item1 100
Inv3 Item3 100 Inv4 04-01-2019 Item2 100
Inv4 Item1 100
Inv4 Item2 100

Query:

SELECT * FROM [DBO].INVOICEHEADERLINE IH  where InvoiceNo IN (SELECT TOP 3 InvoiceNo FROM INVOICEHEADER WHERE  CUSTACCOUNT ='C008-03418'  ORDER BY TRANSDATE DESC) 
Please provide FETCHXML for View or Any Suggestion

*This post is locked for comments

  • Suggested answer
    Kalpavruksh D365 CoE Profile Picture
    2,545 on at
    RE: GET LAST 3 INVOICE WITH ITEMS OF AN ACCOUNT

    Hi Anshuman,

    Use keyword Count instead of TOP which will give you the result. If you will select <fetch count = "2".... , you will get top 3 records from the list.

    Please refer to the following link for your reference.

    crmtipoftheday.com/.../use-top-in-fetchxml

    If found useful, please mark this answer as verified.

  • Community Member Profile Picture
    on at
    RE: GET LAST 3 INVOICE WITH ITEMS OF AN ACCOUNT

    Thanks for your Reply..

    Its true Im not getting other way to achieve this.

    Im trying with this FetchXML. Returns only 3 Records of Items..

    string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' top='3'>

       <entity name='acx_invoiceheader' >

           <attribute name='acx_invoiceno' />

    <attribute name='acx_transdate' />

            <attribute name='acx_name' />

            <order attribute='acx_transdate' descending='true' />

           <filter type='and'>

            <condition attribute = 'acx_salesvalue' operator= 'gt' value = '0'/>

            </filter>

           <link-entity name='account' from='accountid' to='acx_name' visible='false' link-type='outer' alias='a_667c2ecfebb0e711812cc4346bdc5e51' >

               <attribute name='name' />

           </link-entity>

            <link-entity name='acx_invoiceheaderline' from='acx_invoiceno' to='acx_invoiceheaderid' link-type='inner' alias='ab'>

            <attribute name='acx_invoiceno' />

    <attribute name='acx_itemid' />

    <attribute name='acx_netamount' />

    </link-entity>

       </entity>

    </fetch>";

    Any other help....

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: GET LAST 3 INVOICE WITH ITEMS OF AN ACCOUNT

    You can do only left outer join and inner join using fetch Xml.Take a look below reference-

    docs.microsoft.com/.../use-fetchxml-left-outer-join-query-records-not-in

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans