Skip to main content

Notifications

Microsoft Dynamics NAV forum
Suggested answer

How to get Last posting date of items in Item Ledger Entry

Posted on by

Hello Dynamics Community.

I am actually customizing a report where I need to get the last posting date of item in the item ledger entry table whether the entry type is sale, purchase, positive adjmt, negative adjmt, etc....

So my dataitem is the Item Ledger Entry table and I have 3 colums: Item No., Posting Date and Entry Type.

I have defined PostingDate as variable date in C/AL globals.

On PreReport trigger i have inserted this code:

"Item Ledger Entry".SETCURRENTKEY("Item No.","Posting Date","Entry Type");
"Item Ledger Entry".SETRANGE("Item No.","Item Ledger Entry"."Item No.");
"Item Ledger Entry".SETRANGE("Entry Type","Item Ledger Entry"."Entry Type"::" ");
IF "Item Ledger Entry".FINDLAST THEN
 PostingDate:= "Item Ledger Entry"."Posting Date";

But my report is showing all items with their all posting dates. It is not taking the last posting date of an item. It is taking all the posting dates. For example, for an item No. 1100, it has entry type and posting dates as Consumption (9/8/2019), Consumption (9/7/2019),Consumption(9/6/2019) and Postive Adjmt (6/1/2018). The report is taking all these. It is not taking only last entry type and posting date that is Consumption (9/8/2019).

Grateful if someone tell me how can I achieve the following above?

Thanks to help me.

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 69,510 Super User 2024 Season 2 on at
    RE: How to get Last posting date of items in Item Ledger Entry

    Hi, You can modify your code as suggested by Daniele. My suggestion is that you can add Last posting date of item in the item ledger entry like those two standard fields, not used them directly.
    Then after adding the DataItem of Item in the report, you can get it.

    Hope this helps.
    Thanks.

    ZHU

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,217 Moderator on at
    RE: How to get Last posting date of items in Item Ledger Entry

    hello

    declare another var record of the item ledger entry

    example:

    ItemLedgerEntry: 'item ledger entry' record

    and then do this

    ItemLedgerEntry.SETCURRENTKEY("Item No.", "Posting Date", "Entry Type");

    ItemLedgerEntry.SETRANGE("Item No.", "Item Ledger Entry". "Item No.");

    ItemLedgerEntry.SETRANGE("Entry Type", "Item Ledger Entry". "Entry Type"::" ");

    IF ItemLedgerEntry.FINDLAST THEN

    PostingDate:= ItemLedgerEntry. "Posting Date";

    although I don't understand one thing.

    if the code you made is in the onprereport, how do you know which item is the filter'?

    DAniele

  • AJTR Profile Picture
    AJTR on at
    RE: How to get Last posting date of items in Item Ledger Entry

    Hello Mr Zhu,

    Actually my client wants to have the last date when an item has been moved in the report. That is the posting date should contain the last date / recent date of that item which have been moved. 

    Should I take it from the item ledger entry or the physical inventory ledger entry?

    Grateful if you could advise me on this.

    Thanks.

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 69,510 Super User 2024 Season 2 on at
    RE: How to get Last posting date of items in Item Ledger Entry

    Hi, This is the same variable? Or is it the same DataItem?

    I think there is a problem with this Setrange, you have not filtered out the correct value, you can export it to Excel to have a look.

    pastedimage1668644123238v1.png

    pastedimage1668644582179v2.png

    This is the same variable? Or is it the same DataItem? I think there is a problem with this Setrange, you have not filtered out the correct value, you can export it to Excel to have a look.
    As for the last date, you can also refer to the following fields on the Item. With Flowfield, this is also very convenient.

    Hope this helps.

    Thanks.

    ZHU

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,522 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,441 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans