oScript.LinesAdded not working on version 2020

SOLVED

Has anyone been able to use oScript.LinesAdded on a script in version 2020?  I happen to be on 2020 with PU 1.  I'm using it to refresh the grid on the Lines tab in SO Entry after adding lines, but it's not working.  I have to go to another tab and come back in order to get it to refresh.  I have tried a few variations including:

retval = oScript.LinesAdded = -1 'why isn't this refreshing the grid in version 2020?

I have also tried:

retval = oScript.LinesAdded = -1 'why isn't this refreshing the grid in version 2020?
retVal = oScript.LoadGrid("GD_Lines") 'doesn't work to refresh grid
retVal = oUIObj.HandleScriptUI() 'doesn't work to refresh grid

And this is running on a button script on the Lines tab.  Might be a bit different from running it on the Totals/Header tab.

  • +1
    verified answer

    It should be the following.

    retVal = oScript.LoadGrid("GD_Lines")
    oScript.LinesAdded = -1
    retVal = oUIObj.HandleScriptUI()

    However, if you continue to have issues with it, you can try one of the following.  They all check first to see if they are on the Lines tab.  These were all tested on a 2018 install.

    This one attempts to get the object handle to the fldr object and if valid, uses the Redraw method which appears to invoke the current tab's post load logic, which loads the grid, should be equivalent to clicking the Header tab and then clicking the Lines tab.

    If InStr(UCase(oUIObj.GetFolderName()), UCase("pLines")) <> 0 Then
        fldr = 0 : oUIObj.GetValue "fldr", fldr
        If fldr <> 0 Then
            Set fldr = oSession.AsObject(fldr)
            fldr.Redraw
            Set fldr = Nothing
        End If
    End If

    This one uses the oUIObj object's GetValue method to attempt to get the ctl values for the pHeader and pLines tab controls and then uses the oScript.Execute method to execute a compound providex statement which attempts to send the input mimicking the user clicking on the header tab and then the lines tab.

    If InStr(UCase(oUIObj.GetFolderName()), UCase("pLines")) <> 0 Then
        pHeader = 0 : oUIObj.GetValue "fldr.pHeader.ctl", pHeader
        pLines = 0 : oUIObj.GetValue "fldr.pLines.ctl", pLines
        If pHeader <> 0 And pLines <> 0 Then
            oScript.Execute "PREINPUT " & pHeader & "; WAIT 0; PREINPUT " & pLines & "; WAIT 0"
        End If
    End If

    This one uses the oUIObj object's GetControlProperty method to attempt to get the ctl values for the pHeader and pLines tab controls and then uses the oScript.Execute method to execute a compound providex statement which attempts to send the input mimicking the user clicking on the header tab and then the lines tab.

    If InStr(UCase(oUIObj.GetFolderName()), UCase("pLines")) <> 0 Then
        pHeader = 0 : oUIObj.GetControlProperty "fldr.pHeader", "Ctl", pHeader
        pLines = 0 : oUIObj.GetControlProperty "fldr.pLines", "Ctl", pLines
        If pHeader <> 0 And pLines <> 0 Then
            oScript.Execute "PREINPUT " & pHeader & "; WAIT 0; PREINPUT " & pLines & "; WAIT 0"
        End If
    End If

    This one uses the oUIObj object's GetControlProperty method to attempt to get the ctl value for the GD_Lines grid control and then uses several methods to attempt to clear and reload the grid.  However, I have observed that the ClearTotals will cause an error in AR Cash Receipts Entry but works as expected in other tasks like Sales Order Entry and SO Invoice Data Entry.  Likewise, in AR Cash Receipts Entry, the LoadLines method does not accumulate the total like it should when used in tasks like Sales Order Entry and SO Invoice Data Entry.  This observation was on a 2018 install.

    If InStr(UCase(oUIObj.GetFolderName()), UCase("pLines")) <> 0 Then
    	GD_Lines = 0 : oUIObj.GetControlProperty "GD_Lines", "Ctl", GD_Lines ' Get the Control ID for the GD_Lines control.
    	If IsNumeric(GD_Lines) And GD_Lines <> 0 Then ' Check that the grid's control ID is numeric and greater than 0.
    		GD_Lines = CLng(GD_Lines) ' Make sure the value returned from the GetControlProperty method is converted to the type that the following methods expect.
    		oUIObj.ClearGrid GD_Lines ' Clear the grid.
    		oUIObj.ClearTotals ' Clear the totals so we don't continually add the lines totals while loading to the total displayed in the bottom right.  This will cause an error in AR Cash Receipts Entry but works in Sales Order Entry and SO Invoice Data Entry.
    		oUIObj.LoadLines GD_Lines ' Load the lines.  This will not accumulate totals in AR Cash Receipts Entry but will in Sales Order Entry and SO Invoice Data Entry.
    		oUIObj.SetStartingRow GD_Lines ' Go to the last row selected.
    	End If
    End If

  • 0 in reply to David Speck

    Awesome primer!  I will study this.  And the second method worked for this script.  Thank you!!

    This worked:

    If InStr(UCase(oUIObj.GetFolderName()), UCase("pLines")) <> 0 Then
    fldr = 0 : oUIObj.GetValue "fldr", fldr
    If fldr <> 0 Then
    Set fldr = oSession.AsObject(fldr)
    fldr.Redraw
    Set fldr = Nothing
    End If
    End If