Thanks Alnoor, you got me going in the right direction, although i didn't have any luck with TranslateColumns actually making a difference, it didn't cause an error. I did get ShowRow to give me tease of it working but when stepping off the line to a new line or going to a different tab and back, the row wasn't saving regardless of the method used to set the value (SetValue, SetValueNoValidate, InvokeChange, MainGridCtl'Value$)
ShowRow works great if i don't actually want to save the value and just use the column as a place holder to display data retrieved but for this purpose, i do want the value saved.
After a bunch of tracing and watching values, I eventually found the missing link causing all of this grid corruption, it seems sage 100 doesn't call the ClassOnFocusGrid() method before or during the first table script PostRead event and because of this, it throws off some protected variables causing them to lag a row behind. The end result is SetValue and InvokeChange thinking focus is still on the previously selected row.
Using the following code, i can consistently set the value and the header will recognize that the line was changed. InvokeChange would work in place of SetValue but for the target column this will be used for, the column will be locked and InvokeChange doesn't play nicely with locked columns so i'm just using SetValue, end result appears to be the same.
Dim sItemCode
Dim oBusObj_UI
Dim nGD_Lines_Ctl
Dim nGD_Lines_RowsHigh
Dim nGD_Lines_CurrentRow
Dim sCurrentKey
sItemCode = "" : oBusObj.GetValue "ItemCode$", sItemCode
If sItemCode <> "" And oBusObj.EditState = 1 Then
If oScript.UIObj > 0 Then
Set oBusObj_UI = oSession.AsObject(oScript.UIObj)
nGD_Lines_Ctl = 0 : oBusObj_UI.GetControlProperty "GD_Lines", "Ctl", nGD_Lines_Ctl : nGD_Lines_Ctl = CLng(nGD_Lines_Ctl)
If nGD_Lines_Ctl > 0 Then
nGD_Lines_RowsHigh = 0 : oBusObj_UI.GetControlProperty "GD_Lines", "RowsHigh", nGD_Lines_RowsHigh : nGD_Lines_RowsHigh = CLng(nGD_Lines_RowsHigh)
If nGD_Lines_RowsHigh > 0 Then
oScript.DeactivateProcedure "PostRead"
oBusObj_UI.ClassOnFocusGrid nGD_Lines_Ctl
nGD_Lines_CurrentRow = 0 : oBusObj_UI.GetControlProperty "GD_Lines", "CurrentRow", nGD_Lines_CurrentRow : nGD_Lines_CurrentRow = CLng(nGD_Lines_CurrentRow)
If nGD_Lines_CurrentRow > 0 Then
sCurrentKey = "" : sCurrentKey = oBusObj.GetKeyPadded()
oBusObj.SetValue "CommentText$", "Testing"
oBusObj.Write
oBusObj.EditLine sCurrentKey
End If
oScript.ActivateProcedure "PostRead"
End If
End If
Else
oBusObj.SetValue "CommentText$", "Testing"
End If
End If
I found that i could also use oBusObj_UI.SaveRow and oBusObj_UI.GetLineRecord instead of oBusObj.Write and oBusObj.EditLine but the results appeared to be the same. I just needed to make sure after the writing/saving of the line/row, the line/row was put back into edit mode so it didn't cause a disconnect between the grid and ui and the line object.
------------------------------
David Speck II
Tennessee Software Solutions
------------------------------
Original Message:
Sent: 04-03-2019 02:35
From: Alnoor Cassim
Subject: Detail SetValue/InvokeChange causing discrepancies in the grid's row on version 2018 .2 Advanced with JobOps
JobOps overrides SO_SalesOrderDetail_bus and SO_CommonEntryDetail to do "special" things to support their functionality. This means even with mods (non-scripting) on JobOps systems, we don't necessarily get the expected behavior. Let's leave it at that.
Let me ask simpler question of what are you trying to accomplish with the SetValue on PostRead anyway? If changing say Unit Price, maybe you can move that to PreWrite or PostVal of ItemCode ?? Let's pretend you are doing SetValue on UnitPrice. Do you need any normal dict or other validation to fire off OR your own separate PostVal script to fire off when you set UnitPrice? If not, does SetValueNoValidate do the trick?
Let's say it works but doesn't refresh the ExtensionAmt. Then try your normal trick of Write'ing the line then reloading the grid then positioning yourself on the same row (while not recursively firing off your PostRead) but here is something else to look into.
When MDs / DPs change developer fields on lines and don't want to have to reload the whole grid, they take advantage of what happens in standard code when you change the Qty Ordered. Have you ever wondered why when you change the Qty, the ExtensionAmt refreshes yet w/o a full reload of the grid?
Trace it then look at how ChangeQuantityOrdered() in SO_CommonEntry_UI runs, how it runs ShowRow() and how it runs TranslateColumns(). I've never tried it with script.
To recap:
- Knowing you can't control JobOps induced stuff, can you use PreWrite or PostVal of ItemCode instead?
- Do you need any normal validation or new script firing off on the col being set? If not, can you do SetValueNoValidate() instead?
- If SetValueNoValidate() works except for grid cells not refreshing, use one of the two ways to refresh.
Hope that helps.
------------------------------
Alnoor Cassim
Free Agent Developer and Consultant
CallForHelp.biz
Email: alnoor@callforhelp.biz
Orange County, CA
------------------------------