Web Services

Insert a New Record Using External Web Service

Description
This customization shows how to use a web service to update data from a web service-based data source. This provides an alternate way to access data than the database stored procedure and inline SQL normally generated by Iron Speed Designer.
Variables
Table Name
Select the database table
Primary Key
Select the primary key field in the table
First Updatable Field
Select an updatable field in the table
Second Updatable Field
Select another updatable field in the table
Applies to
SQLAccessClass class
Code
 
''' 
''' InsertRecord makes use of Web Service to insert a record.
''' 
''' The table to insert into.
''' The record data to insert.
''' Nothing, or the new  of the inserted record.
Public Overrides Function InsertRecord(ByVal table As _
    BaseClasses.Data.TableDefinition, ByVal recVal _
    As BaseClasses.Data.RecordValue, ByVal columnsChanged() As Boolean) _
    As BaseClasses.Data.KeyValue

    Dim ${First Updatable Field} As String
    Dim ${Second Updatable Field} As String

    ' Get the instance of data access class.
    Dim my${Table Name} As ${${Table Name}ClassName}
    my${Table Name} = ${${Table Name}ClassName}.Instance
    Dim col As BaseColumn

    For Each col In table.ColumnList
        Dim index As Integer = table.ColumnList.IndexOf(col)
        If (col.InternalName = my${Table Name}.${First Updatable Field}Column.InternalName) Then        
            ${First Updatable Field} = col.ToDatabaseValue(recVal.ColumnValues(index)).ToString()
        ElseIf (col.InternalName = my${Table Name}.${Second Updatable Field}Column.InternalName) Then        
            ${Second Updatable Field} = col.ToDatabaseValue(recVal.ColumnValues(index)).ToString()
        End If
        
        ' Set the values of additional columns        
        ' If a column in database allows null values, then check for null values.
        ' Phone field in Shippers table allows null value. If the user does not enter any
        ' value for phone while adding a new record then you need to add additional condition here
        ' as shown below.
        
        ' ElseIf (col.InternalName = myShippers.PhoneColumn.InternalName) Then
        '     If (recVal.ColumnValues(index).IsEmptyString) Then
        '         Phone = ""
        '     Else
        '         Phone = col.ToDatabaseValue(recVal.ColumnValues(index)).ToString()
        '     End If
        ' End If
        
    Next

    ' Instantiate the object that will communicate with a web service.
    ' Replace MyWebServiceForTableAccess with your web service name.
    Dim webService As New localhost.MyWebServiceForTableAccess
    webService.Credentials = System.Net.CredentialCache.DefaultCredentials

    ' Call the web service's "AddRecord" function.
    Dim ${Primary Key} As Integer = _
    webService.Add${${Table Name}RecordClassName}(${First Updatable Field}, _
    ${Second Updatable Field})

    Dim retKeyValue As New KeyValue
    retKeyValue.AddElement( _
    my${Table Name}.${Primary Key}Column.InternalName, _
    ${Primary Key}.ToString())
    Return retKeyValue    
End Function
     

Terms of Service Privacy Statement