UI event script, scrolling through order lines on panel post load, corrupts line entry

SOLVED

(Tested on v2017.2 Standard and 2018.3 Standard).

I stripped my script to just a loop through oLines on a panel UI script (see below script code).  With this active, when I add / edit lines, then click off the tab then back to pLines, the lines on an order are overwritten / deleted by the new lines (i.e. corruption).

Set oLines = oSession.AsObject(oBusObj.Lines)
retVal = oLines.MoveFirst()
do until oLines.EoF
    retVal = oLines.MoveNext()
loop ' oLines

Goal:

I want to scroll through lines, and pop-up a message to the user under certain conditions, but just scrolling through oLines with a Panel - PostLoad script is causing problems.

In theory, since I'm already on the lines tab (and only want to check for a certain item code being on the order), I could use the grid to do that, but I have not scrolled through grid lines via script before.  Any ideas / tips would be appreciated.

  • 0

    Hi Kevin,

    The "corruption" is because as part of standard operating the UI does exactly what your loop does in that it reads through each line loading it in the grid and then adds a new blank line and does a Lines.AddLine() to put the last line in a new record state.  However, your script then executes looping through the lines and leaving the last line in memory, so at this point the UI and the business object are out of sync.  So if you add a new line at this point it will actually overwrite the last line.  So you could check to see if you're on the last row of the grid and do the oLines.AddLine() yourself.

    Now, I think what might be better for your particular issue, might be to do a post-read event to scan through the lines and then store in a storage variable the indicator.  Then when you do your post-load event check that storage variable and display your message to the user.  You may want to have another script when you write each line checking for whatever you are checking for in the existing lines.

    Let me know if that makes sense, and if you need any assistance let me know.

    Elliott

  • 0 in reply to jepritch

    Thanks for the explanation Elliott.  I knew it had to be something like that.

    The idea of multiple scripts and storage variables is a good one, but I'm hoping to find a way to handle it all in one script (with the business purpose I am trying to meet... pop-up a reminder to add a certain comment code line, if it doesn't exist and the customer record requires it).

    If the oLines.AddLine() does not work I think I might just try moving the script to the Totals tab instead.  That could satisfy this customer requirement.

  • +1 in reply to Kevin M
    verified answer

    Kevin,

    You could probably just check the oLines.EditState and get the current key for the record before doing your loop through the lines, then based on Editstate = 2 you could do the AddLine() or if it was = 1 then you could do a EditLine() or SetKey() using the saved key.  That would ensure you were on the same key before your logic and then put it back after.

    Let me know how it goes, always interested in practical application of this stuff Slight smile

    Elliott

  • +1 in reply to jepritch
    verified answer

    I think I have something working.  (Not extensively tested...).  With your explanation that the Lines object is being left on a different line by my loop, grabbing the line key at the beginning, then resetting it after the loop, seems to put things back in place.

    retVal = oBusObj.GetValue("SalesOrderNo$", sSalesOrderNo)
    Set oLines = oSession.AsObject(oBusObj.Lines)
    retVal = oLines.GetValue("LineKey$", sLoadLineKey)
    retVal = oLines.MoveFirst()
    do until oLines.EoF
        retVal = oLines.MoveNext()
    loop ' oLines

    if sLoadLineKey <> "" then ' set oLines back to the original value.
        retVal = oLines.SetKey(sSalesOrderNo & String(7-Len(sSalesOrderNo),Chr(0)) & sLoadLineKey)
    end if

  • 0 in reply to Kevin M

    Hey Kevin,

    You can grab the entire key of the line instead.  Try:

    sLoadKey = ""
    sLoadKey = oLines.GetKey()

    ...

    if sLoadKey<>"" Then
       retVal = oLines.SetKey(sLoadKey)
    End If

    The index it is using is kDISPLAY, which is SalesOrderNo + LineSeqNo + LineKey

  • 0 in reply to jepritch

    Hey Elliott,

    Thanks for the additional suggestion.  I've already put the script onto the customer system for testing, but if there are any issues that arise I'll try your code changes.