MapName Method for LCFieldlist

This method maps fields with different names. Use this method for field mapping operations when the fieldnames are different in the source and target. This allows you to change field order and also exclude fields.

No new LCField objects are created by this method. Instead, the destination list contains references to the same LCField objects that are in the source list. If you assign a field in one list, the corresponding field in the other list is automatically assigned to the same value because they share the same storage. This lets you fetch records from one connection and immediately write them out to another connection, without copying values from one fieldlist to another.

Defined In

LCFieldlist

Syntax

Call destList. MapName (sourcelist, nameList, mapList)

Parameters

Parameter

Description

sourcelist

LCFieldlist. The fieldlist to map fields from.

nameList

String. A comma separated list of the names of the original fields from sourceList. This need not include all the fields from sourceList, nor do they have to be in the same order as they appear in sourceList.

mapList

String. A comma separated list of the new field names to place in destList, in the order in which they should appear. It should contain the same number of field names as nameList does, and the fields will be mapped to the original fields in the corresponding positions in nameList. For example, if nameList contains "a, b, c" and mapList contains "d, e, f", then field "a" in sourceList corresponds to field "d" in destList, field "b" corresponds to field "e", and so on.

Example

Option Public
Uselsx "*lsxlc" 
Sub Initialize
  Dim session As New LCSession
  Dim srcCon As New LCConnection ("db2") 
Dim destCon As New LCConnection ("notes")
  Dim fetchLst As New LCFieldList
  Dim insertLst As New LCFieldList
  Dim count As Long
  REM set the appropriate properties to connect to the data sources
  srcCon.Database = "Gold"
  srcCon.Userid = "JDoe"
  srcCon.Password = "xyzzy"
  srcCon.Metadata = "customer"
  destCon.Server = "Rainbow"
  destCon.Database = "Gold"
  destCon.Metadata = "customer"
  REM connect to the two data sources
  srcCon.Connect
  destCon.Connect
  srcCon.FieldNames = "ContactName, CompanyCity, CompanyState"
  If (srcCon.Select (Nothing, 1,  fetchLst) <> 0) Then
    ' map the result set from the SELECT with the desired names in the destination.
    Call insertLst.MapName (fetchLst, _
    "ContactName, CompanyCity, CompanyState", _
    "Name, City, State")
      ' set the property MapbyName on the target.
    ' this is necessary if the fields in the form are
    ' (or might be) in different order than they appear in destCon.
    destCon.MapByName = True
      While (srcCon.Fetch (fetchLst, 1, 1) > 0)
      count = count + destCon.Insert (insertLst, 1, 1)
    Wend
    Print "Transferred " & count & " records from DB2, to Notes"
    Print "Field mapping from (DB2 column name to Notes Field name):"
    Print "     ContactName   -->  Name"
    Print "     CompanyCity   -->  City"
    Print "     CompanyState  -->  State"
  End If
End Sub

Example Output

Transferred 3 records from DB2, to Notes
Field mapping from (DB2 column name to Notes Field name):
     ContactName   --> 	Name
     CompanyCity   -->  	City
     CompanyState  -->  	State