tU_tsoSOLineDist

SOLVED

Hello,

I recently made a similar post to this one regarding the insert version of this trigger, tI_tsoSOLineDist. Our issue was resolved and we are now able to save the original ShipDate entered so when the date changes, we can see by how much. 

However, that solution saves the shipdate when the order is first entered and unacknowledged. We would instead like to save the date only after the order is acknowledged and open. Any subsequent changes in the date from this point would then be visible. 

I wonder if we should use this update trigger instead? I've seen this code:  IF NOT UPDATE(UpdateDate), would something like this work to set the condition of when the order moves from unacknowledged to open? 

The code used to insert the record from the insert trigger is:

insert into tsosalesorderorigshipdate_exi (solinedistkey, origshipdate)
select solinedistkey, shipdate
from inserted, tsosoline with (nolock), tsosalesorder with (nolock)
where inserted.solinekey = tsosoline.solinekey
and tsosoline.sokey = tsosalesorder.sokey
and tsosalesorder.trantype = 801

  • 0
    verified answer

    Hi,

    If you want to track shipdate changes when your order is acknowledged and open, you may consider using update trigger. Place the following code into your update trigger, it will insert a record of the original shipdate only when the order status is open and shipdate is changed:

    if not exists(select * from tsosalesorderorigshipdate_exi where solinedistkey in (select solinedistkey from inserted))
    insert into tsosalesorderorigshipdate_exi (solinedistkey, origshipdate)
    select deleted.solinedistkey, deleted.shipdate
    from inserted, deleted, tsosoline with (nolock), tsosalesorder with (nolock)
    where inserted.solinekey = tsosoline.solinekey
    and inserted.solinedistkey = deleted.solinedistkey
    and inserted.shipdate <> deleted.shipdate
    and tsosoline.sokey = tsosalesorder.sokey
    and tsosalesorder.trantype = 801
    and tsosalesorder.status = 1

    Hope this helps.

    If you need more assistance feel free to contact me.

    Thanks,

    Garik Melkonyan

    www.GarikMelkonyan.com

  • 0 in reply to garmel

    Hello.

    Thanks for that! I understand the logic with 'if not exists', but I don't understand the reference to 'deleted'. Why are you linking to 'deleted'?

  • 0 in reply to sabian

    In update triggers, the deleted table holds the snapshot of the original records being updated. And here the deleted table is used to check if shipdate is changed during the update.

    Thanks,

    Garik Melkonyan

    www.GarikMelkonyan.com

  • 0 in reply to garmel

    Ok, after testing I see that now. It only saves the reference to the original ship date, if the ship date gets changed after the sales order is open.

    Thank you for your help!