BOI During Daily Sales Reports & Updates

SOLVED

I have a simple script that updates a UDF in AR_Customer. The script is a Table Pre-Write event on AR_Customer.
It works perfectly when editing a customer record in Customer Maintenance.
It does not work though when the Daily Sales Reports & Updates are run. That process does edit the AR_Customer records, but the script simply won't run.

Why would it run fine in one scenario, but not the other?

If anyone has ideas, it would be much appreciated!


Here is my script:
r = 0
PriceLevel = ""
If oSession.UserCode <> "ORO" Then
r = oBusObj.GetValue("PriceLevel$",PriceLevel)
If PriceLevel = "1" or PriceLevel = "4" Then
r = oBusObj.SetValue("UDF_SendToOro$","Y")
End If
End If

  • 0

    Simple answer is that journal/register updates do not trigger *-write event scripts.

    I can't remember specifically, but while experimenting a while back, i think i recall seeing either a pre or post delete event script triggered on either the SO_SalesOrderHeader, SO_SalesOrderDetail, SO_InvoiceHeader, or SO_InvoiceDetail table when doing an update one time.

    So you might be able to experiment with it and it would just mean that if a customer exists more than once on an invoice, your script would be triggered for each one.

  • 0 in reply to David Speck

    I'd try a pre-validate column trigger... perhaps date of last activity (or something like that).  I've done something similar for updating SO by script, as invoices are posted (last invoice number).

  • 0 in reply to David Speck

    On my v2018 install, attaching the following script to the SO_SalesOrderHeader, SO_SalesOrderDetail, SO_InvoiceHeader, and SO_InvoiceDetail tables' pre-delete and post-delete events did give me evidence that the delete events do indeed get triggered during the update.


    oScript.DebugPrint "Procedure: " & oScript.GetCurrentProcedure() & " | " & "Table: " & oBusObj.GetTable("Main") & " | " & "Key: " & """" & oBusObj.GetKey() & """"


    Here's the trace from when i updated an SO Invoice without a sales order.

    Here's the trace from when i updated an SO Invoice with a sales order.

  • 0 in reply to David Speck

    Every attempt I've made to open a different business object during a journal update has been a disaster.

  • 0 in reply to Kevin M

    That was a good thought Kevin so i got curious and attached my script to the following AR_Customer events and did another round of SO updates but none of them were triggered.

  • +1 in reply to Kevin M
    verified answer

    With the following script on the post-delete of the SO_InvoiceHeader and the CurrentProcedure script shown in the other replies on the AR_Customer table, i was able to update the customer record.


    ARDivisionNo = "" : oBusObj.GetValue "ARDivisionNo$", ARDivisionNo
    CustomerNo = "" : oBusObj.GetValue "CustomerNo$", CustomerNo
    oScript.DebugPrint "" & ARDivisionNo & "-" & CustomerNo
    If ARDivisionNo <> "" And CustomerNo <> "" Then
    AR_Customer_Bus = oSession.GetObject("AR_Customer_Bus")
    If AR_Customer_Bus > 0 Then
    Set AR_Customer_Bus = oSession.AsObject(AR_Customer_Bus)
    AR_Customer_Bus.SetKeyValue "ARDivisionNo$", ARDivisionNo
    AR_Customer_Bus.SetKeyValue "CustomerNo$", CustomerNo
    If AR_Customer_Bus.SetKey() = 1 Then
    Comment = "" : AR_Customer_Bus.GetValue "Comment$", Comment
    AR_Customer_Bus.SetValue "Comment$", Comment & "1"
    AR_Customer_Bus.Write
    AR_Customer_Bus.Clear
    End If
    Set AR_Customer_Bus = Nothing
    End If
    End If


    Here's the trace.

    Kevin, you likely had issues with getting a handle to another object not associated with the journal update task which may have required first doing an oSession.SetProgram to set the security before hand. I have no idea how doing this during the update would affect other aspects of the update so i tested it without it.

    It is important to at least check that the value returned from the GetObject is greater than 0, if not, you were not able to get the object handle.

    The above example is quick and dirty and should not be used for production until proven tested. You'll notice i did not use any type prefixes for the variable names and the only returned value i checked was the one from the SetKey method to make sure i was selecting an existing record and no errors occured preventing me from doing so.

  • 0 in reply to David Speck

    This is perfect!  Thank you guys for the help.  I was able to attach a script to the Post-Delete event on the SO_InvoiceHeader and update the AR_Customer record in a similar fashion to the way you described above.

    Thanks for all the help and input!