Skip to Content

Table mapping - source object change

Hello,

is there any way how to change the source object of Table Mapping? I need to switch the source object of already existing mapping to a new source table (with exactly same set of columns). With my model (see image 01)

I tried following:

Changing the TargetObject of the shortcut representing the source table in the target model was not enough (see image 02, missing lines, source table in the mapping Unavailable).

sourceTab.ChangeTargetObject NewSourceTable

So I tried inserting new source model into the SourceModels collection of the appropriate DataSource first (=creates new source model in the TargetModels collection) and manually creating the shortcut of new source table into the target model. Result was the same, none of these helped (see image 02).

ds.SourceModels.Insert -1, newSourceMdl
Set newShortcut = newSourceTable.CreateShortcut(Mapping.Package)
sourceTab.ChangeTargetObject NewSourceTable

So my question is, is it possible to change the source table of a TableMapping from one source table to another (in different model)? Or do I have to duplicate the TableMapping with new source and then delete the original mapping? How to deal with ColumnMappings if I succeed with the TableMapping? They will/should be gone when I modify the parent object.

Thanks in advance for any advice,

Ondrej

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • May 25 at 08:23 PM

    To make changeTargetObject work, you need make sure the shortcut you have created from the mapping is showing up in your current model By default, the symbol is hidden. Go to Symbol->Show / Hide Symbols. Check the symbol.

    Or you can run the following script : (Table_1 is the shortcut created by the mapping)


    for each tbl in activeModel.tables
    if tbl.name = "Table_1" and tbl.IsShortCut() then
    if activeDiagram.findSymbol(tbl) is nothing then
    activeDiagram.attachObject(tbl)
    else
    for each symbol in tbl.symbols
    symbol.hidden = false
    next
    end if
    tbl.ChangeTargetObject NewSourceTab, false
    end
    next

    ChangeTargetObject has two arguments. I guess the second one should allow to preserve column mapping if the value is false, but it doesn't

    work . So you have to write code to do column mapping.

    Fortunately this is not hard. Before execute above code, you can run the following code to get column mapping info

    ActiveModel.GetCollectionByKind PdPdm.cls_TableMapping, TableMappings

    for each tabMap in TableMappings

    set columnMaps = tabMap.columnMaps

    for each colMap in columnMaps

    output colMap.Column.name & " mapped to " & colMap.mappedTo

    next

    next

    Store the mapping info, create the column mappings.

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Phillip,

      thanks for your reaction. Are you 100% sure, that to make ChangeTargetObject work, I have to display a symbol of the shortcut of source table on the diagram??

      I know, that I can always re-create/duplicate the mappings manually (by script, of course), but this is the last chance for me how to do it, because of the high risk that something will go wrong or I will omit something in the mappings re-creation.

      Ondrej