Zero the Qty. On Sales Order (Item Card)

slmaluwaslmaluwa Member Posts: 366
Hi there

We need to zero the Qty. On Sales Order field in the item card. I wrote small code to update "Sales Line" table. Part of it below
   SL.MODIFYALL("Outstanding Quantity", 0);
   SL.MODIFYALL("Qty. to Invoice",0);
   SL.MODIFYALL("Qty. to Ship",0);
   SL.MODIFYALL("Outstanding Qty. (Base)", 0);
   SL.MODIFYALL("Qty. to Invoice (Base)",0);
   SL.MODIFYALL("Qty. to Ship (Base)",0);

Now, it successfully ZEROed all items. But, what I am worried about it is whether it will make any other area to work incorrectly. I dunno I am doing the correct thing.
Also, is there any other areas/tables I should update this information?

Please help me.

Thank you

Maluwa
"A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."

Answers

  • ara3nara3n Member Posts: 9,256
    could you tell us why you are trying to do this?

    Btw you should not write you code this way, you are not running the business logic.

    The goal when you write code is to mimic how a you would do it manually.

    The field on item card is a flowfield that looks for the sum of outstanding qty (base) on sales line.

    So a user cannot see the outstanding qty (base) field on sales line. This field is calculated when you ship or change the qty field on sales order.

    So you need to set the quantity field to what ever you have shipped.


    Your code will loop through sales line.
    SalesLine.setrange("No.",ItemNo);
    salesline.setrange("Document type",order);
    salesline.setrange(type,Item);
    loop through it
    //some things to work with. You have to reopen the order if it's released.
    //validate the quantity to "Quantity shipped"
    //Modify(true);
    until salesline.next = 0;


    By following how a user would do it, you are ensuring that you've followed the proper process and run the business logic, so you don't have to think on what else you have missed. And there could be a lot of things.

    Serial no tables,
    Lot no
    reservation
    warehouse shipments documents
    the existing sales lines have base qty fields that are still the same.
    oustanding amount fields on sales line
    etc, etc
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • slmaluwaslmaluwa Member Posts: 366
    Thank you for your quick reply.

    The reason for doing this is to plan on required qty on Sales Orders.
    Our system has lot of pending orders (partially invoiced) and customer doen't neet them any more. We don't see a way to delete this pending orders from the Navision.

    I actually did filter as you have done and but did not loop through Sales Line.

    I don't fully understand the following lines from your code suggestion
    //some things to work with. You have to reopen the order if it's released.
    //validate the quantity to "Quantity shipped"
    //Modify(true);

    How do I do this validation (will it make the "Outstanding Qty. (Base)" to zeo?) and what does modify(true) do. Please note that I am not an expert coder but have done customization to a certain extent.
    "A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."
  • kinekine Member Posts: 12,562
    Your code made your database inconsistent:

    On sales line, the Quantity=Outstanding quantity + Shipped Quantity but because you zeroed Outstanding quantity, it is not true and it can lead to problems in future. If you need to say "this line will not be shipped anymore", change the Quantity too (Quantity = Quantity - Outstanding Quantity) and do it with calling the Business logic (through Validate). Else you can have problems with reservations, tracking etc.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • slmaluwaslmaluwa Member Posts: 366
    Hi Rashed & Kamil

    After a few trials, I now understand what you both have mentioned. I have modified the code and still testing it on a test DB. Once satisfied, I will post a reply here.

    Thank you
    "A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."
  • SavatageSavatage Member Posts: 7,142
    slmaluwa wrote:
    We don't see a way to delete this pending orders from the Navision.

    you can't delete them?
  • slmaluwaslmaluwa Member Posts: 366
    I think I can't delete them directly.
    But, if I can follow the above method and update the lines, it is possible to DELETE them all.
    "A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."
  • DenSterDenSter Member Posts: 8,305
    Simply setting those values to zero will create BIG problems!! Delete your test database, create a new one, and approach this in a different way.

    You should be able to delete sales orders once the quantity shipped is equal to the quantity invoiced. If you have an order that has 10 shipped and 5 invoiced, then you need to invoice the remaining 5, and at that point you should be able to delete the sales order.
Sign In or Register to comment.