Button Script to delete Sales order with cancel code

Hello all,

I wrote a script with the goal to delete sales orders with a specific condition. So I can delete sales orders just fine its just that when the orders are deleted the cancel reason code is not flowing to history it is staying blank. I am even providing the value in the script. This is a button script that sits on Tab 1 of SO entry. I have tried a variation of code to force the UI (sCancelReasonCode = "" : oUIObj.InvokeLookup "SO_CancelReason", sCancelReasonCode) to bring up the cancel reason window and then it does go to history with a a code but the order status is left as "A". I would really like to just press the button it finds the orders I want to delete and it just goes to history with the cancel code I have chosen in the code. Code below. Any help would be appreciated.

Parents
  • sMsg = ""
    sItem = ""
    sDItem = ""
    CustDiv = ""
    CustNo = ""
    sSP = ""
    sSO=""
    sPO=""
    sOT=""
    sStatus=""
    sCode=""
    If UserCode = "VAB" or UserCode = "SDM" or UserCode = "KNT" or UserCode = "DSP" or UserCode = "JLN" or UserCode = "CLJ" or UserCode = "DAB" or UserCode = "REE" or UserCode = "SNN" or UserCode = "CMV" or UserCode = "NAT"or UserCode = "KNM" then
    Dim retVal
    retVal = oBusObj.GetValue("SalesOrderNo$", sSO)
    sMsg = "You are about to delete Sales Orders please make sure that the Div and Cust and Order Type are right in the Code." + Chr(13)+ Chr(10)+ Chr(13)+ Chr(10)+" Proceed?"
    retMsg = oSession.AsObject(oSession.UI).MessageBox(".Y2", sMsg)

    If retMsg = "NO" then
    sMsg = "Deletion has been canceled"
    retMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
    retVal = oScript.SetError ("Delete Canceled")
    ElseIf retMsg = "YES" then
    sMsg = "Last chance to cancel please make sure that the Div and Cust and Order Type are right in the Code.!" + Chr(13)+ Chr(10)+ Chr(13)+ Chr(10) & " Proceed?"
    retMsg = oSession.AsObject(oSession.UI).MessageBox(".Y2", sMsg,"icon=!")
    If retMsg = "NO" then
    sMsg = "Deletion has been canceled"
    retMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
    retVal = oScript.SetError ("Delete Canceled")
    ElseIf retMsg = "YES" then

    Dim oSales
    Set oSales = oSession.AsObject(oSession.GetObject("SO_SalesOrder_bus"))
    retVal = oSales.MoveFirst()
    do while oSales.EOF <> 1
    retVal = oSales.GetValue("ARDivisionNo$", CustDiv)
    retVal = oSales.GetValue("CustomerNo$", CustNo)
    retVal = oSales.GetValue("OrderType$", sOT)
    retVal = oSales.GetValue("CustomerPONo$", sPO)
    retVal = oSales.GetValue("SalesOrderNo$", sSalesOrderNo)
    IF sPO = "RSK" then
    retVal = oSales.SetValue("OrderStatus$", "H")
    'retVal = oSales.SetValue("CancelReasonCode$", "RSK")
    retVal = oSales.SetValue("CustomerPONo$", sPO & " Completed")
    retVal = oSales.Write()
    retVal = oSales.Delete()
    retVal = oSales.MoveNext()
    Else

    retVal = oSales.MoveNext()

    End If


    Loop
    sMsg = "All Sales order for your Criteria have been deleted."
    retMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
    End If
    End if
    End IF

  • in reply to David Speck

    Hello David, Thats where I got some of the code to start with to invoke the cancel reason panel to populate but, the thing is I want the code to go to history without involving that window. I am trying to pass the value in my code above.

Reply
  • in reply to David Speck

    Hello David, Thats where I got some of the code to start with to invoke the cancel reason panel to populate but, the thing is I want the code to go to history without involving that window. I am trying to pass the value in my code above.

Children