I'm trying to write a script to track (in a UDF) how much freight has been charged already for an SO.
When I try to trigger the update on the SO Header table (filtered for oSession.Updating = 1), using the LastInvoiceOrderNo, it doesn't work because the SO_InvoiceHistoryLink table entry hasn't been written yet (for querying the invoice HeaderSeqNo) when the script is triggered.
I then thought to set up a trigger on AR Invoice History Header, but those scripts are linked to AR_InvoiceHistoryInquiry_bus, which (apparently?) doesn't execute during a sales journal update.
AR_TransactionPosting is unavailable for script triggers.
I'd prefer to use proper primary key values when opening other tables in a script, but aside from the ideas above the only method I can think of is a partial key SetBrowseFilter lookup using the KSALESORDER index in invoice history (without the HeaderSeqNo). I'm thinking this "should" always provide the correct invoice record, but before I go rewriting my script for that I'm wondering if there's a better way.
Any ideas?