Open Forum

Expand all | Collapse all

Copy A Sales Order and Edit Original and Copy using AL

  • 1.  Copy A Sales Order and Edit Original and Copy using AL

    TOP CONTRIBUTOR
    Posted Oct 19, 2019 12:04 PM
    Hi All

    Fairly new to Dynamics 365 BC. Written a few small AL extensions (adding a few fields, custom reports and queries).

    I need to write a function that will copy a sales order with all lines where qty to ship is > 0 (think of it like releasing from a blanket). The sales person will fill out Qty to ship on each line and then go to an Action in the ribbon and select "Copy Order Lines" ( I could do it from a new sales order (they would enter the source order) if it simplifies things a lot)

    The copy should have identical header, and each line where qty to ship was > 0. The copied lines' qty will be the qty to ship in source order. I then need to decrement the qty to ship from the original order

    So if I have the following source order

    Line    qty    qty to ship
    1      1000      100
    2      2000        0
    3      3000      300


    The new line order should have

    Line    qty      qty to ship
    1       100         100
    3      2700        2700

    The old order should have

    Line     qty    qty to ship
    1        900         0
    2       2000         0
    3       2700         0

    I read the old design pattern for CopyDocs, but it's all C/SIDE

    I know about code unit 6620, but have never worked with code units.

    I read a bit about Copy and TransferItems, and it seems Copy is way to go (AFAIK, TransferItems is generally used for transferring items between dissimilar docs (e.g. order to shipment or order to invoice)

    Can anyone point me in the right direction?

    Thanks

    Mark

    ------------------------------
    Mark Anderson
    Director of ERP Systems
    Clesen Wholesale
    Evanston, IL
    ------------------------------
    Conference-BCNAVUG_200x200


  • 2.  RE: Copy A Sales Order and Edit Original and Copy using AL

    TOP CONTRIBUTOR
    Posted Oct 20, 2019 12:41 AM
    What would be really helpful is the story behind what you want to accomplish.  As I read what you're trying to do, the blanket sales order functionality sounds exactly like what you're trying to do.  Is there a reason that is not the desired approach?  Codeunit 6620 is the correct codeunit invoked when the copy documents function is called.  You could insert some code to limit the copy of the lines to only those with quantity to ship values, but as you stated, that would originate from a new sales order and not fro the source sales order.

    ------------------------------
    David Wiser
    Project Manager
    Tigunia
    Seattle WA
    ------------------------------

    Conference-BCNAVUG_200x200


  • 3.  RE: Copy A Sales Order and Edit Original and Copy using AL

    TOP CONTRIBUTOR
    Posted Oct 21, 2019 09:02 AM
    Thanks David

    I presume best practice is copy the code unit and make our own versions.

    Blanket sales orders won;t work for us as the we have a agricultural add-in that has it's own availability views and these do not look at blanket orders when looking at demand.

    Thanks

    Mark

    ------------------------------
    Mark Anderson
    Director of ERP Systems
    Clesen Wholesale
    Evanston, IL
    ------------------------------

    Conference-BCNAVUG_200x200


If you've found this thread useful, dive deeper into User Group community content by role