Is it possible to trigger a script when a PO line is deleted?

Hi All,  I have a client that wants to prevent users from deleting a COMPLETED line on a PO.   It appears that we can't do this via scripting  but wanted to confirm before I send it to programming.    

And just a note - there are all kinds of problems with this request but this client has some weird business practices.  

Bob Osborn
ACI Consulting

Top Replies

  • 0
    Seems simple enough of a concept, but of course until tested it's never a sure thing. Pre-delete trigger, check your logic and SetError if you want to block the deletion. The problem I see if that you'll have to filter out when the system deletes the lines properly / automatically, and only block manual deletion attempts.
  • 0 in reply to Kevin M

    Hey   

    I have a script similar where I trigger a message box when some deletes a line on SO.

    It has a post-delete trigger. My only problem is when someone needs to delete the whole order, the message box will come up once for each line on the SO before it will delete the order. Is there any way around that?

  • 0 in reply to Brown0987

    I don't know of a way to detect whether the SO is actively being deleted, from a line script.

    Perhaps replace the panel's Delete button with your own Delete+, where you SetStorageVar... (then invoke the Sage button), and in your line script add a GetStorageVar (looking for what you set in the button script) for a filter.

    (Be sure to add a filter to prevent your script from running during a journal update, where SO lines get deleted as they are invoiced).

  • 0 in reply to Kevin M

    Ok I can try that. 

    What sort of filter would keep it from running during journal update? 

    I have it set to run for only certain users for that reason..is there a better way?

  • 0 in reply to Brown0987

    If you use  's suggestion of using a button script this will not be executed as part of the Journal Update.  However, if you do only want to do something when run from the data entry UI and not executed when the update is run there is a flag you can use.  The Updating property of the Session object.  If an update is being run then this variable will have a numeric value.

    If oSession.Updating = 0 Then

        ' Run script code

    End if

  • 0 in reply to Kevin M

    Alright  I tried it that way but I guess the storagevar isn't passing through?

    I'm still getting the messagebox when deleting order. 

    Here's my button script:

    oSessionScript = 0
    Set oSessionScript = oSession.AsObject(oSession.ScriptObject)
    retVal = oSessionScript.SetStorageVar("sOrderDelete", "Y")


    retVal = oScript.InvokeButton("BT_DELETE")
    retVal = oUIObj.HandleScriptUI()

    And here's the lines script:

    if oSession.CompanyCode = "MBT" Then

    sType = ""
    sSalesOrderNo = ""
    sSessionUserCode = oSession.UserCode
    sOrderDelete2 = ""


    retVal = oBusObj.GetValue("SalesOrderNo$",sSalesOrderNo)
    Set oSvc = oSession.AsObject(oSession.GetObject("SO_SalesOrder_svc"))
    retVal0 = oSvc.find(sSalesOrderNo)
    retVal1 = oSvc.GetValue("PaymentType", sType)

    oSessionScript = 0
    Set oSessionScript = oSession.AsObject(oSession.ScriptObject)
    retval = oSessionScript.GetStorageVar("sOrderDelete",sOrderDelete2)

    if sType = "PYPAL" OR sType = "AFFIRM" AND sOrderDelete2 <> "Y" Then

    retStrVal = oSession.AsObject(oSession.UI).MessageBox("","This order contains a DEPOSIT."&vbNewLine&vbNewLine&"Please update DEPOSIT amount to reflect changes!","title=Deposit Type Order!,icon=STOP")

    end if
    end if

     You see anything I'm doing wrong?

  • 0 in reply to Brown0987

    These are the notes I have for those commands between objects, but I've never tried it starting with a button script.  I'd strip everything down to bare bones and see if just this works, without any extraneous logic.

    The oScript version of these commands only work within the same business object.  For different business objects (like line scripts and tier distribution scripts… or header / lines… use this strategy.

     

    oSessionScript = 0

    Set oSessionScript = oSession.AsObject(oSession.ScriptObject)

    retval = oSessionScript.SetStorageVar("YourVariableName", sTheValueToSend)

     

    oSessionScript = 0

    Set oSessionScript = oSession.AsObject(oSession.ScriptObject)

    retval = oSessionScript.GetStorageVar("YourVariableName", sTheValueReceived)