Forcing Cancellation Code when deleting Sales Orders into history through BOI

SOLVED

Good morning all,

So I figured this would have been a relatively easy script but I can't seem to find a way of accomplishing what I need.

I have a customer that would like to force a cancellation reason whenever you delete a Sales Order into history.  They currently have the "Retain Deleted Sales Order" setting to Prompt in SO Options, which first prompts the user if they would like to delete the order (standard), but THEN it asks "Do you want to save the deleted order in history?"  If you say yes, it's all good.  However, you can say No and it will delete the order and not save it (a BIG no no for the customer).  Furthermore, if you do click Yes to save to history, then it bring up this screen to enter the Cancellation Code:

Cancellation Code reason

While I have the Cancellation Code as a required field in Advanced Settings for UDF and Table Maintenance, it will not force an entry unless I validate the field with a list I create, which I would have to make it match the existing lookup on this field.  If I don't have validation, the user can simply click OK without a code and it will delete it.

So I was thinking my quick fix would be to set "Retain Deleted Sales Order" setting to Yes, then create a Table - Pre Delete script that would launch the Cancellation Code screen above BEFORE it asks to delete the order.  I figured that by doing this, the Cancellation Code would be written into the table and then the order would be deleted into history.
Unfortunately, I cannot seem to find the correct UI to bring that screen.  This is the code I had tried but it brings up Cancel and Reason Code Maintenance On The Fly.   

oSOCancel = 0

oSOCancel = oSession.GetObject("SO_CancelReasonCodeOTF_UI")
Set oSOCancel = oSession.AsObject(oSOCancel)
retVal = oSOCancel.Process()

I tried the SO_CancelReasonCode_UI object as well, but that brings up the standard Cancel and Reason Code Maintenance.  
Is there a way of bringing up that specific screen?  I had also tried using the InvokeButton to bring up "fldr.DCANCEL" (Cancellation Code screen in SO_SalesOrder.M4L library) but I had no luck.  Maybe I was using the wrong code?  Any ideas or suggestions would be highly appreciated.

Thanks in advance!
Javier

Parents
  • 0

    Instead of trying to launch the panel, you might be better off invoking the SO_CancelReason lookup instead. I'm not sure if this will actually work in a UDS as long as you have a handle to the UI object, such as oSession.AsObject(oScript.UIObj).InvokeLookup but if it does, you will want to make sure you are actually filtering for very specific details, such as the UI being present in the first place, can use oScript.UIObj <> 0, the start program, might want to make sure it is SO_SalesOrder_UI, make sure oSession.Updating = 0, etc.

    Another way to do this might be to use oSession.AsObject(oScript.UIObj).NomadsProcess "DCANCEL", "SO_SalesOrder.M4L" but you may need either a UI post exit script or a fake OK button to run a button script to capture the value entered in the field so you can set it into a storage variable using oSession.AsObject(oSession.ScriptObject).SetStorageVar. You would then use oSession.AsObject(oSession.ScriptObject).GetStorageVar in your original script to get the value that was entered. You could then loop if the value returned is blank in case the user just tried to click OK or Cancel. 

    I would try the InvokeLookup first though as it will be much cleaner and efficient. The first argument is the lookup name, i believe "SO_CancelReason" should give you what you want. The second argument is the variable you want the select value returned in. Make sure you initialize the variable as a blank string before you pass it to the method.

  • 0 in reply to David Speck

    Awesome, thanks for the great info as always .  I'm going to take it and run with it.  If I stumble (I'm sure I will), I'll post a reply.  

  • 0 in reply to Javier Guzman

    My concern would be that anything set in a script during the Pre-Delete event might not make it into SO History.

  • 0 in reply to Kevin M

    Good point, may actually have to move to a post delete and attempt to update the history record afterwards. I haven't messed with history and pre deletes much.

Reply Children