Finding Available Inventory when posting sales order

slmaluwaslmaluwa Member Posts: 364
hello

I am trying to get the available qty of an item at a particular location at the time posting the order. Earlier another developer has used ItemLedgerEntry as follows:
dvQTY := 0;
    recItemLedger.RESET;
    recItemLedger.SETCURRENTKEY("Item No.","Entry Type","Variant Code","Drop Shipment","Location Code","Posting Date");
    recItemLedger.SETRANGE("Item No.",recSalesLine."No.");
    recItemLedger.SETRANGE("Variant Code",recSalesLine."Variant Code");
    recItemLedger.SETRANGE("Location Code",recSalesLine."Location Code");
    recItemLedger.SETFILTER("Remaining Quantity",'<>0');

    
    IF recItemLedger.FIND('-') THEN BEGIN
      REPEAT
        DVQty := DVQty + recItemLedger."Remaining Quantity";
      UNTIL recItemLedger.NEXT = 0;
    END;

Now, can't I do the same think in a much faster way using this method?
recItem.RESET;
    recItem.SETRANGE("No.",recSalesLine."No.");
    recItem.SETFILTER("Location Filter",recSalesLine."Location Code");
    IF recItem.FIND('-') THEN
       recItem.CALCFIELDS(Inventory);

    DVQty := recItem.Inventory;
    recItem.RESET;

Do you see any mistake here. I think it doesn't return the qty as required.
"A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."

Comments

  • i4tosti4tost Member Posts: 208
    Yes, you miss Variant code.
    Actually it is better to use CALCSUMS in original developer code :)
  • slmaluwaslmaluwa Member Posts: 364
    Hi
    Yes, I missed it. Actually, I am yet to understand what exactly this Variant means? Never came across it and the company also only interested in the cost of item in a location

    So, suppose, I also add "Variant filter". Which code you recommend to use?
    "A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."
  • nunomaianunomaia Member Posts: 1,153
    Or trying to be perfect replace FIND(‘-’) with a FINDFIDST
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • ara3nara3n Member Posts: 9,256
    dvQTY := 0;
        recItemLedger.RESET;
        recItemLedger.SETCURRENTKEY(change this key to to what that has the following fields and  has remaining qty as sumindex field);
        recItemLedger.SETRANGE("Item No.",recSalesLine."No.");
        recItemLedger.SETRANGE("Variant Code",recSalesLine."Variant Code");
        recItemLedger.SETRANGE("Location Code",recSalesLine."Location Code");
       recItemLedger.SETRANGE(Open,,true);
       recItemLedger.calcsums("remaining quantity");
      dvQTY :=  recItemLedger."remaining quantity";
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kapamaroukapamarou Member Posts: 1,152
    Why do you need this? If it is just informative then ok.
    Where is it going to be used?
Sign In or Register to comment.