If i were you, i would handle this all in a single button script in item maintenance, i don't really see a need for a script on either of the delete events on SO_SalesOrderDetail.
I think you should start by getting object handles to the following objects.
- SO_SalesOrderDetail_Bus (this will be used to locate the current item code on open sales orders or you can use ODBC)
- SO_SalesOrder_Bus (this will be used to handle the actual deletion of the lines on open sales orders)
- SO_SalesOrderHistoryInquiryDetail_Bus (this will be used to update the CancelReasonCode for the deleted lines)
You should be able to first get an object handle to SO_SalesOrderDetail_Bus and set the browse filter index to either "kItemType" or "kItemWhse" then set the browse filter to the current item code + chr(0), alternatively, you could use ODBC to return the lines with the current item code. This will allow you to easily use MoveFirst, MoveNext and EoF to loop through the lines for the current item code. Make sure to Clear after getting the key values you need so you don't lock the record when deleting the line using the SO_SalesOrder_Bus object.
Then get a handle to SO_SalesOrder_Bus and proceed through each sales order and as Alnoor said, prior to deleting the line, get the value of SalesOrderNo and SOHistoryDetlSeqNo, proceed with deleting the line and writing the header, then use SalesOrderNo and SOHistoryDetlSeqNoin in the SetKey of the object handle for SO_SalesOrderHistoryInquiryDetail_Bus and set the value for the CancelReasonCode and write the line.
As long you aren't changing quantities or amounts, you shouldn't have to worry about totals on the header getting out of sync since you are letting the header handle those updates when deleting the line.
Don't forget to include some Clear methods where needed.
------------------------------
David Speck II
Tennessee Software Solutions
------------------------------
Original Message:
Sent: 03-25-2020 11:46
From: David Speck II
Subject: Script command to delete SO line, and have a line reason code in SO history
That's too bad, think it would have been the cleanest way to make it happen too.
Thanks
David Speck
TSS
Sage | Sage 100 Certified Consultant
Original Message------
Pre-write on SO_SalesOrderHistoryDetail does not seem to trigger... I'm going to try a new object within the same script (to update SO history with the reason code).
Thanks for the ideas David. I will post an update after I've tried a few things.
------------------------------
Kevin Moyes
Technical Systems Analyst
Munjal White Consulting Co.
Toronto ON
------------------------------