BBjRecordSetMappingSource Example

declare BBjRecordSet UserRS!
declare BBjRecordSet MapRS!
GOSUB SetupRecordSets

rem 'configure our source and fallback action
source! = UserRS!.createRecordSetMappingSource(MapRS!,"CODE","DESC")
?"MappingSource type: ",source!.getType()
?"MappingSource backField: ",source!.getBackField()
?"MappingSource frontField: ",source!.getFrontField()
?"MappingSource RecordSet: ",source!.getRecordSet()
end

printRecord:
    name$ = UserRS!.getCurrentRecordData().getFieldValue("NAME")
    location$ = UserRS!.getCurrentRecordData().getFieldValue("MAPPED_LOC")
    PRINT name$, " lives in the ", location$
return

SetupRecordSets:
    UserRS! = BBJAPI().createMemoryRecordSet("NAME:C(100*=10),LOCATION:C(1)")
    Data! = UserRS!.getEmptyRecordData()
    Data!.setFieldValue("NAME", "John Doe")
    Data!.setFieldValue("LOCATION", "1")
    UserRS!.insert(Data!)
    Data! = UserRS!.getEmptyRecordData()
    Data!.setFieldValue("NAME", "Jane Smith")
    Data!.setFieldValue("LOCATION", "3")
    UserRS!.insert(Data!)
    Data! = UserRS!.getEmptyRecordData()
    Data!.setFieldValue("NAME", "Jane Doe")
    Data!.setFieldValue("LOCATION", "2")
    UserRS!.insert(Data!)
    Data! = UserRS!.getEmptyRecordData()
    Data!.setFieldValue("NAME", "Dr Droopy")
    Data!.setFieldValue("LOCATION", "0")
    UserRS!.insert(Data!)

    rem ' Create the recordset to use for mapping LOCATION to something more screenfriendly.
    MapRS! = BBjAPI().createMemoryRecordSet("CODE:C(1),DESC:C(20*=10)")
    Data! = MapRS!.getEmptyRecordData()
    Data!.setFieldValue("CODE","0")
    Data!.setFieldValue("DESC","NORTH")
    MapRS!.insert(Data!)
    Data! = MapRS!.getEmptyRecordData()
    Data!.setFieldValue("CODE","1")
    Data!.setFieldValue("DESC","SOUTH")
    MapRS!.insert(Data!)
    Data! = MapRS!.getEmptyRecordData()
    Data!.setFieldValue("CODE","2")
    Data!.setFieldValue("DESC","EAST")
    MapRS!.insert(Data!)
    Data! = MapRS!.getEmptyRecordData()
    Data!.setFieldValue("CODE","3")
    Data!.setFieldValue("DESC","WEST")
    MapRS!.insert(Data!)
return