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

Parents
  • 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

Reply
  • 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

Children