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
  • Final Code

    'Deletes all CSPs
    UserCode = MAS_SCR_USR
    PriceCodeRec = ""
    PriceCode = ""
    sMsg = ""
    ExpireDate = ""
    sYDate = Year(date) & Right("0" & Month(date),2) & Right("0" & Day(date),2)
    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

    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)


    IF Left(sPO,13) = "RSK Completed" then
    retVal = oSales.SetValue("OrderStatus$", "H")
    retVal = oSales.SetValue("CancelReasonCode$", "RSK")
    'retVal = oSales.SetValue("CustomerPONo$", sPO & " Completed")
    retVal = oSales.Write()
    oSales.SaveDeletedReason = "RSK"
    'oBusObj.Delete sSalesOrderNo
    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 Bareus16

    This is a button script in Sales Order Entry, correct?  

    If yes, there is no need to get a separate object handle to SO_SalesOrder_Bus when you can use oBusObj.  However, since it is a button script and buttons added via Customizer are normally only enabled when a record is loaded, you should use the methods in the other thread to make sure to save or clear the current record before looping through the records.

  • in reply to David Speck

    yes a button in Sales Order Entry. OK I will look at them thank you for all of the help!

Reply Children
No Data