B4J Question ABMaterial Table_Changed fired Twice

walterf25

Expert
Licensed User
Longtime User
Hello everyone, i am working on an Inventory web app for work using ABMaterial version 4.3. and I am using a table inside a tab, the table has a few editable cells, when the user enters a value in one of the editable cells, I noticed that the Table_Changed(Params As Map) functions gets raised two times.

As a result the database gets updated twice, does anyone have any idea why this functions is fired twice, and how to avoid that from happening, I know I can create a flag and just update my database based on that flag, but i don't really think that's the best solution, below is the code that gets executed inside the tbl_changed(Params as Map) function.
Table_Changed:
Sub tbl2_Changed(Params As Map)
    Dim row As String = Params.Get("row")
    Dim column As String = Params.Get("column")
    Dim Value As String = Params.Get("value")
    Log("Table2 Changed [" & row & " " & column & "] = " & Value)
    Dim fields As Map
    Dim wherefields As Map
    wherefields.Initialize
    wherefields.Put("Item_Number", "'"&(row+1)&"'")
    fields.Initialize
    If column = 6 Then
        fields.Put("Qty_Taken", "'"&Value&"'")
        Dim updatequery As String
        updatequery = DBM.BuildUpdateQuery("HermosaProtoA", fields, wherefields)
        Dim updateresponse As Int
        updateresponse = DBM.SQLUpdate(DBM.GetSQL, updatequery)
    Log("update response: " & updateresponse)
        
    Dim tabs As ABMTabs = page.Component("tabs")
    Dim cont As ABMContainer = tabs.GetTabPage(tabs.GetActive)
        Dim tbl2 As ABMTable
        Dim balance As Int
        tbl2 = cont.Component("tbl2")
        tbl2.PrepareTableForRetrieval
        balance = tbl2.GetString(row, 5)
        tbl2.SetString(row, 5, (balance - Value))
    '''    tbl2.RefreshRow(row)
        Dim updatequery As String
        Dim fields As Map
        Dim result As Int
        Dim wherefields As Map
        fields.Initialize
        wherefields.Initialize
        fields.Put("Balance", "'"&(balance-Value)&"'")
        wherefields.Put("Item_Number", "'"&(row+1)&"'")
        updatequery = DBM.BuildUpdateQuery("HermosaProtoA", fields, wherefields)
        result = DBM.SQLUpdate(DBM.GetSQL, updatequery)
        Log("updated balance query response: " & result)
    End If
End Sub
Any suggestions?

Thanks,
Walter
 

walterf25

Expert
Licensed User
Longtime User
Could it be possible because of this line? Maybe it raises again a _Changed() event.
Not sure, I will try to check by commenting this part out, if that is the case, what other alternatives are there to update that specific cell then?

Walter
 
Upvote 0
Top