Set Field Values

Initialize New Record from Existing Record

This example demonstrates how to initialize values in a Page, based on values from an existing record, essentially implementing a copy record function. This example assumes you are passing the primary key value of the existing record as a URL parameter.
Table Name
Select the name of the database table
Primary Key
Select Primary key field in the selected database table
Initialization Field
Select the database field that corresponds to the control that needs to be initialized.
Initialization Field Control
Select the control that needs to be initialized.
Record Control Class
Select the record control where this customization will be inserted
Applies to
RecordControl class
''' Override DataBind(),call mybase Databind() to populate the UI
''' controls using the DataSource and then initilize the values of
''' field control
Public Overrides Sub DataBind()

    'Call MyBase.DataBind()
    If (Not Me.Page.IsPostBack) Then
        ' Get the key from the URL.
        Dim keyFromUrl As String = me.Page.Request.QueryString("Initfrom${Table Name}")

        ' keyFromUrl variable will contain a parameter string as follows
        ' InitfromEmployees=4 or InitfromEmployees=<...xml parameter definition...>
        ' set this url for New button in a page with table control.
        If Not IsNothing(keyFromUrl) AndAlso (Trim(keyFromUrl).Length > 0) Then

            ' Create the where clause.
            Dim wc As WhereClause = new WhereClause()
            Dim recId As String = keyFromUrl
            If (KeyValue.IsXmlKey(recId)) Then
                ' Key are typically passed as XML structures to handle composite keys.
                ' If XML, then add a Where clause based on the Primary Key in the XML.
                Dim pkValue As KeyValue = KeyValue.XmlToKey(recId)
                wc.iAND(${${Table Name}ClassName}.${Primary Key}, BaseFilter.ComparisonOperator.EqualsTo, pkValue.GetColumnValue(${${Table Name}ClassName}.${Primary Key}).ToString())
                ' The URL parameter contains the actual value, not an XML structure.
                wc.iAND(${${Table Name}ClassName}.${Primary Key}, BaseFilter.ComparisonOperator.EqualsTo, recId)
            End If

            ' Get existing record based on primary key.
            Dim rec As ${${Table Name}RecordClassName}()  = ${${Table Name}ClassName}.GetRecords(wc, Nothing, 0, 2)
            If (rec.Length > 0) Then
                ' Populate each field value based on existing record's values.
                Me.${Initialization Field Control}.Text = rec(0).${Initialization Field}.ToString()
            End If
        End If
    End If
End Sub


Terms of Service Privacy Statement