UI Script Post Load Event on Sales Order Lines Tab

SOLVED

Hi Experts,

I have a UI script that is attached to the Post Load event of the Sales Order Lines tab. It works fine if click on the tab. But when I am already on the Lines tab and move to the next Sales Order by clicking the NEXT button, then the tab keeps focus and the Post Load event doesn't fire.

I guess I could programmatically move to another tab and back. But is there a better way to trigger this event when moving through Sales Orders?

How do I tell which tab I am on when a SO got loaded?

Thanks for your help.

Best,

B.

  • 0

    Can you not use the SO_SalesOrderHeader table's post read event?

    As for determining which tab you are on, see the GetFolderName method in this sample code from the scripting.docx file.

    ' Recommended UI detection - if no UI then do not use any type of MsgBox or other UI.
    ' This is important because if your script pops a MsgBox during an automated process
    ' such as an import, or webservices running as a background process, the service will hang.
    
    If (IsObject(oUIObj)) Then
    	' This is either a UI Event Script or a Button link script
        ' – because oUIObj is directly available.
    	MASUI = True
    	screenName = oUIObj.GetScreenName()
    	panelName = oUIObj.GetPanelName()
    	folderName = oUIObj.GetFolderName()
    Else
    	' This is a Business Event script. Must test if UI is present/available
    	MASUI = CBool(oScript.UIObj)
    	If (MASUI) Then
    		' Need to get my own handle to access oUIObj functionality such as InvokeChange(), InvokeLookup(), Etc.
    		Set myUIObj = oSession.AsObject(oScript.UIObj)
    		screenName = myUIObj.GetScreenName()
    		panelName = myUIObj.GetPanelName()
    		folderName = myUIObj.GetFolderName()
    		Set myUIObj = Nothing
    	End If
    End If
    
    currentProc = oScript.GetCurrentProcedure() ' Available in both UI and Business Events - no need to check for UI.
    
    If MASUI Then
    	' Ok to Message box
    	uiContext = "Current Proc: " & currentProc & vbCRLF & "Screen Name: " & screenName & vbCRLF & \
        "Panel Name: " & panelName & vbCRLF & "Folder Name: " & folderName
    	' Always use Sage 100 MessageBox instead of VbScript MsgBox() to avoid msg appearing on
    ' the server where no one can click on it
    	oSession.AsObject(oSession.UI).MessageBox "", uiContext
    Else
    	' Not Ok to Message box
    	tableName = oBusObj.GetTable("main")
    	busContext = "Current Proc: " & currentProc & " - Table Name: " & tableName
        ' But Ok to print to Trace Window.
    	oScript.DebugPrint busContext
        ' And A-Ok to write to the activity log.
        oSession.WriteLog "A", "Yay! Scripting can write to the activity log! " & busContext
    End If
    

    What you might have to do in the table's post read event is check if on the pLines or pLinesW tab and then either run the code that you are using in your post load script or try to trigger the post load event by calling either the ui object's PostLoadLines or PostLoadPLines method. There is also a method of the ui object's script object that can be used to call a script but i'm not well versed in its arguments.

  • 0 in reply to David Speck

    Hi David,

    Thanks for your input on this one. I am coloring lines with the script. That is why I am running it as a UI Script on the PostLoad of the LinesTab. I can change the script and run it on the PostLoad of each line. But that can't be as efficient. With the current script, I create object handles only once. When I put it on the lines, this will happen for each line.

    I tried the PostLoadPLines() on the Sales Order Header PostLoad. It gives the lines grid an extra flicker but doesn't trigger the UI script. Switching to another tab and back (via script) also doesn't trigger the event.

    Here is the script that I used to test:

    MASUI = CBool(oScript.UIObj)
    If (MASUI) Then
    	Set myUIObj = oSession.AsObject(oScript.UIObj)
    	sFldr = myUIObj.GetFolderName()
    	If sFldr = "PLINES" Then
    		'retVal = oScript.InvokeButton("fldr.pAddress")
    		retVal = oScript.InvokeButton("fldr.pHeader")
    		retVal = oScript.InvokeButton("fldr.pLines")
    		'retVal = myUIObj.PostLoadPLines()
    	End If
    	Set myUIObj = Nothing
    End If

    Edit:

    I just tried another thing. I added a button to the lines panel that executes the UI script. It works when I manually click the button. When I click the button from the above script, it errors out with "unable to access ms script file".

    Edit 2:

    Calling the button script programmatically is working when I put the button on DMAIN instead of the Lines tab. Here is the final script:

    MASUI = CBool(oScript.UIObj)
    If (MASUI) Then
    	Set myUIObj = oSession.AsObject(oScript.UIObj)
    	sFldr = myUIObj.GetFolderName()
    	If sFldr = "PLINES" Then
    		retVal = oScript.InvokeButton("BT_LINK_12")
    	End If
    	Set myUIObj = Nothing
    End If

  • +1 in reply to BillyVanilli
    verified answer

    In panels that can switch between the standard view and widescreen view, you have to check if the folder name is either pLines or pLinesW. You can either just check the left 6 characters or you can do an InStr function. I usually use the UCase function on the variable and text to find just to avoid case sensitive issues when evaluating.

    FYI, using InvokeButton on the folder tabs doesn't work the way you want it to when used back to back. I don't think i ever got the desired effect like that. You can try throwing the oUIObj.HandleScriptUI method after each InvokeButton but i don't think that will work either. Has to do with how the oScript object queues buttons to invoke if i recall correctly.

    Also, the PostLoad doesn't exist for tables, i believe you meant PostRead but just clarifying.

  • 0 in reply to David Speck

    That is good advice. I thought about the PLINES / PLINESW issue and believe that I had tested. It did work, so I assumed that the method just returns PLINES, even for PLINESW. But I might have not tested correctly.

    I have used the LCASE/UCASE in the past as well (and I put it back in after your suggestion). I had not done so to avoid unnecessary operations. If something is returned as UpperCase, I would hope that it is returned as UpperCase everywhere, even in different versions. I assume that UCase/LCase are not very expensive to execute on short variables. Debugging on the other hand could be a nightmare.

    The button only gets invoked once per Sales Order (Table Post-Read). I tested it on the switch between multiple Sales Orders, and it works as desired when you click through SOs.. 

    And you are correct, I meant Post-Read for the table.

    Thanks again for all your input on this!

    Bastian

  • 0 in reply to BillyVanilli

    Hi , if the suggested answer helped, be sure to mark it as verified, thank you!