UI Script drops first line

SOLVED

Experts,

I have a complex script that fires on the Panel PostLoad event of PLINES in SO Entry. The script colors lines based on some conditions and works great. It is based on a script that I got from a ScriptingClass a few years ago. The issue with my script (as well as the example script) is that it will drop the first line item on a new order. An existing order that has been saved before will drop the first new line if you add additional lines. The script loops through the lines.

Does anyone know how to prevent this behavior?

I already tried using the following to set the focus back to the proper line after the loop:

sLoadKey = oLines.GetKey()
...LOOP...
retVal = oLines.SetKey(sLoadKey)


Thanks,

Bastian

  • 0

    If you are reloading the lines or cycling through the lines, it is likely that any changes to the line that is getting dropped is not being committed/written by your script so when the grid is reloaded or you come back to the line, its previous state was cleared.

  • 0 in reply to David Speck

    On a new SO, the script runs the first time before I have any lines. Then I enter lines and go to the Totals tab. Then I go back (the script runs again), but the first line is gone.Isn;t it strange that the first line is gone, not the last?

  • 0 in reply to BillyVanilli
    SUGGESTED

    It might be the fact that you are using SetKey instead of EditLine but there is a nuance to EditLine in that it doesn't work on a sales order who's lines have never been committed to the physical file.  SetKey on a detail object doesn't seem to work the way you would expect it to on the header object or a table that doesn't have a header and detail relation.  So the result is that you are causing a disconnect between the grid's lines's keys and the memory table records' keys.  I don't have access to my test system at the moment so this is about all I can respond with at the moment.

  • +1 in reply to David Speck
    verified answer

    Put the LineKey in the grid to verify the line is truly being dropped (there when you click to Totals, then gone when you come back to Lines), instead of just being overwritten (LineKey still there, but with different values).

    If you are adding lines, be sure to call: oScript.LinesAdded

  • +1 in reply to Kevin M
    verified answer

    I got it to work with Kevin's advice to use retVal = oLines.AddLine() Here are the relevant parts of the script for future reference:

    retVal = oLines.MoveFirst()
    nCurrLine = 0
    Do Until cBool(oLines.Eof)
    	...
        retVal = oLines.SetValue("UDF_XXX$",sXXX)
        retVal = oLines.SetValue("UDF_YYY",nYYY)
        retVal = oLines.Write()
    	
    	If ... Then
    		sBackColour = "RGB: 255,77,77" 'Red
    	ElseIf ... Then
    		sBackColour = "RGB: 77,195,255" 'Blue
    	ElseIf ... Then
    		sBackColour = "RGB: 170,255,128" 'Green
    	ElseIf ... Then
    		sBackColour = "DEFAULT"
    	End If
    
    	If sBackColour <> "" Then
    		colNo = ""				
    		oUIObj.GetControlProperty "GD_LINES", "Column", colNo				
    		oUIObj.SetControlProperty "GD_LINES", "Column", "0"                 'set column number / 0 for all columns
    		oUIObj.SetControlProperty "GD_LINES", "Row", CStr(nCurrLine)        'select row
    		oUIObj.SetControlProperty "GD_LINES", "Backcolour", sBackColour     'ser the color
    		oUIObj.SetControlProperty "GD_LINES", "Column", colNo               'reset column number
    	End If
    
    	retVal = oLines.MoveNext()
    Loop
    
    
    retVal = oLines.AddLine()