Script to update child line

SOLVED

I wrote a script sales order detail post write script that creates a child line that is a percentage of the parent line. If the updates the parent line quantity, unit price or extension the script updates the child line, BUT does not display the change in the grid until you go to another tab, then back to the lines. I have tried using the add line function, but still does not refresh the grid line.  

'Get Values from parent line

Set oUI = oSession.AsObject(oSession.UI)

retval = oHeaderObj.getvalue("ARDivisionNo$",ARDiv)
retval = oHeaderObj.getvalue("CustomerNo$",Customerno)
retval = oBusObj.getvalue("SalesOrderNo$",SalesOrderNo)
retval = obusObj.getvalue("LineKey$",ParentLineKey)
retval = obusObj.getvalue("QuantityOrdered",Quantity)
retval = oBusObj.getvalue("UDF_TARIFF_AMT",TariffAmt)
retval = obusObj.getvalue("UDF_TARIFFLINEKEY$",ChildLineKey)

if Quantity <> 0 then UnitPrice = TariffAmt / Quantity

'Locate child line

if ChildLineKey <> "" then


retVal = oBusObj.MoveFirst()

do until cBool(oBusObj.EOF)


retval = obusObj.getvalue("LineKey$",LineKey)


'Checks if the line is the child
if Linekey = ChildLineKey then


retVal = oBusObj.SetValue("QuantityOrdered",Quantity)
retVal = oBusObj.SetValue("UnitPrice",UnitPrice)
if retval <> 1 then oui.messagebox(oBusObj.LastErrorMsg)
retVal = oBusObj.Write()

'Refresh the grid
oScript.LinesAdded = -1
oScript.LoadGrid "GD_Lines"

End if

oBusObj.movenext
loop


End if

Any help would be greatly appreciated.

Justin 

Parents
  • 0

    I think i have a solution somewhere for this.

    Also, you should probably place you oBusObj.Write between a oScript.DeactivateProcedure and oScript.ActivateProcedure line so you don't end up recursively looping through the lines.

    Here are more details on the two methods from the scripting.docx.

    retVal = oScript.ActivateProcedure
    (proc_name as String)


    and


    retVal = oScript.DeactivateProcedure
    (proc_name as String)

    These are used to give the script author the ability to avoid recursive calls. For example, if the PostValidateQuantityShipped(col, val) procedure script was to invoke the oBusObj.SetValue(“QuantityShipped”, val), this would in turn cause the PostValidateQuantityShipped(col, val) procedure to be called again. To avoid this, call retVal = oScript.DeactivateProcedure(“PostValidateQuantityShipped”) prior to the SetValue() call, then use the retVal=oScript.ActivateProcedure(“PostValidateQuantityShipped”) to reactivate this procedure.

    Note: Use retVal = oScript.DeactivateProcedure(“*ALL*”) to deactivate/activate all procedures for the current business object.

    Note: Use retVal = oScript.Deactivate(“*”) to deactivate/activate the current procedure.

    EDIT: Removed code that wasn't working and removed redundant info that can be obtained from my latest answer.

  • 0 in reply to David Speck

    Hi David,

    I still am unable to have the grid refreshed. When I added the following code I receive the the error below.  

    If oScript.UIObj > 0 Then
           oSession.AsObject(oScript.UIObj).LoadGrid "GD_Lines"
          oSession.AsObject(oScript.UIObj).LinesAdded = -1
    End If

    Also what is the difference from the code above to :

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

  • 0 in reply to justinaroberts

    Think i messed up those two lines, the idea is to get the script object for the UI object, sometimes, you can only accomplish certain things from the UI object's context.

    Give me a few minutes and i'll dig up my solution for the grid refresh.

Reply Children
  • 0 in reply to David Speck

    Here is a verified method to refresh the grid from a table event script. I recommend placing this as close to the end of your script as possible and not in the middle of a loop on the lines.

    If oScript.UIObj > 0 Then
    	Set oSOUIObj = oSession.AsObject(oScript.UIObj)
    	GD_Lines = 0 : oSOUIObj.GetControlProperty "GD_Lines", "Ctl", GD_Lines 
    	If IsNumeric(GD_Lines) And GD_Lines > 0 Then
    		GD_Lines = CLng(GD_Lines)
    		oSOUIObj.ClearGrid GD_Lines
    		oSOUIObj.ClearTotals
    		oSOUIObj.LoadLines GD_Lines
    		oSOUIObj.SetStartingRow GD_Lines
    	End If
    	Set oSOUIObj = Nothing
    End If