Forum Discussion

Ashu_Aswal's avatar
Ashu_Aswal
New Contributor III
8 months ago

Need a sample code for SqlTableEditorSaveData function to restrict saving No value from drop down

I am looking for a sample code for SqlTableEditorSaveData function to restrict saving No value from my SQLtable editor drop down. I have Yes, No  and Yes_optional in my drop down but I don't want user to save No option as yes and no are based on some value criteria but they can select Yes_Optional.

 

 

 

  • Hi Ashu,

    Here's a sample, hope this is of some help

    Case Is = DashboardExtenderFunctionType.SqlTableEditorSaveData
       If  args.FunctionName.XFEqualsIgnoreCase("VerifyRecords") Then
           Dim saveDataTaskInfo As XFSqlTableEditorSaveDataTaskInfo = args.SqlTableEditorSaveDataTaskInfo
           Dim saveDataTaskResult As New XFSqlTableEditorSaveDataTaskResult()
           If Not saveDataTaskInfo.EditedDataRows Is Nothing
               For Each xfRow As XFEditedDataRow In saveDataTaskInfo.EditedDataRows
               
                   If Not xfRow.InsertUpdateOrDelete.Equals(DbInsUpdateDelType.Delete)
                       'Based on your column you can check for values
                       Dim sColValue as string = xfRow.ModifiedDataRow.Item("ColName").ToString 
                       If not sColValue.XFEqualsIgnoreCase("Yes")
                           saveDataTaskResult.IsOK = False
                           saveDataTaskResult.ShowMessageBox = True
                           saveDataTaskResult.Message = "Does not meet criteria"
                           saveDataTaskResult.CancelDefaultSave = True 'Note: Use True if we already saved the data rows in this Business Rule.
                           Return saveDataTaskResult
                       End if
                   End If
                   
               Next
           End If
       End If
    
       Using dbConn As DbConnInfo = BRApi.Database.CreateDbConnInfo(si, saveDataTaskInfo.SqlTableEditorDefinition.DbLocation, saveDataTaskInfo.SqlTableEditorDefinition.ExternalDBConnName)
           dbConn.BeginTrans()
           BRApi.Database.SaveDataTableRows(dbConn, saveDataTaskInfo.SqlTableEditorDefinition.TableName, saveDataTaskInfo.Columns, saveDataTaskInfo.HasPrimaryKeyColumns, saveDataTaskInfo.EditedDataRows, True, False, False)
           dbConn.CommitTrans()
       End Using
    
       saveDataTaskResult.IsOK = True
       saveDataTaskResult.ShowMessageBox = False
       saveDataTaskResult.Message = ""
       saveDataTaskResult.CancelDefaultSave = True
       
       Return saveDataTaskResult
       
    End Select

    Thanks,

    Sudarshan

  • sudarshan's avatar
    sudarshan
    New Contributor III

    Hi Ashu,

    Here's a sample, hope this is of some help

    Case Is = DashboardExtenderFunctionType.SqlTableEditorSaveData
       If  args.FunctionName.XFEqualsIgnoreCase("VerifyRecords") Then
           Dim saveDataTaskInfo As XFSqlTableEditorSaveDataTaskInfo = args.SqlTableEditorSaveDataTaskInfo
           Dim saveDataTaskResult As New XFSqlTableEditorSaveDataTaskResult()
           If Not saveDataTaskInfo.EditedDataRows Is Nothing
               For Each xfRow As XFEditedDataRow In saveDataTaskInfo.EditedDataRows
               
                   If Not xfRow.InsertUpdateOrDelete.Equals(DbInsUpdateDelType.Delete)
                       'Based on your column you can check for values
                       Dim sColValue as string = xfRow.ModifiedDataRow.Item("ColName").ToString 
                       If not sColValue.XFEqualsIgnoreCase("Yes")
                           saveDataTaskResult.IsOK = False
                           saveDataTaskResult.ShowMessageBox = True
                           saveDataTaskResult.Message = "Does not meet criteria"
                           saveDataTaskResult.CancelDefaultSave = True 'Note: Use True if we already saved the data rows in this Business Rule.
                           Return saveDataTaskResult
                       End if
                   End If
                   
               Next
           End If
       End If
    
       Using dbConn As DbConnInfo = BRApi.Database.CreateDbConnInfo(si, saveDataTaskInfo.SqlTableEditorDefinition.DbLocation, saveDataTaskInfo.SqlTableEditorDefinition.ExternalDBConnName)
           dbConn.BeginTrans()
           BRApi.Database.SaveDataTableRows(dbConn, saveDataTaskInfo.SqlTableEditorDefinition.TableName, saveDataTaskInfo.Columns, saveDataTaskInfo.HasPrimaryKeyColumns, saveDataTaskInfo.EditedDataRows, True, False, False)
           dbConn.CommitTrans()
       End Using
    
       saveDataTaskResult.IsOK = True
       saveDataTaskResult.ShowMessageBox = False
       saveDataTaskResult.Message = ""
       saveDataTaskResult.CancelDefaultSave = True
       
       Return saveDataTaskResult
       
    End Select

    Thanks,

    Sudarshan