Developer forum

Forum » Integration » Creating new columns to populate by a table script

Creating new columns to populate by a table script

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

What is the recommended approach to invent / create new columns that can be populated by a table script on an integration job? Let's say I have three custom fields:

IsInternational
HasColor
CanBuyOnline

In a table script I like to populate their values with some custom logic (based on the values of other columns for example). How would I go about doing that? It seems that in order to set the destination column's value (bound to one of the custom fields) I need to create a *source* column in the table script. However, the source doesn't exist in the mapping and therefore not in the table script.

Any ideas? Adding a new column mapping gives me a new mapping row where I can select my custom field as the destination, but I can't select an empty / new source.

Imar

 


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Imar,

you can do this inse the TableScript ProcessInputRow method. Once you get into ProcessInputRow first time you can use the code like that,
it will add a new column to the source table:

Schema result = job.Source.GetOriginalSourceSchema();
table = result.GetTables().FrstOrDefault();
table.AddColumn(new Column("IsInternational", typeof(string), table));

Then add a new mapping from source column to destination:
Mapping mapping = job.Mappings.Find(m => m.DestinationTable.Name == "YourTableName");
                    if (mapping.GetColumnMappings().Find(cm => string.Compare(cm.DestinationColumn.Name, "IsInternational", true) == 0) == null)
                    {
                        Column IsInternationalColumn = job.Source.GetSchema().GetTables().Where(table => some condtion to find the IsInternational column from table.Columns).First().Columns.First();
                        mapping.AddMapping(IsInternationalColumn, job.Destination.GetSchema().GetTables().Find(t => t.Name == "YourTableName").Columns.Find(c => string.Compare(c.Name, "IsInternational", true) == 0), true);
                    }

Once the mapping is added you can cache some flag so it will not be added again, then in the ProcessInputRow write the code to fill in the row["IsInternational"] with some value.
Hope that should work.
Kind regards, Dmitrij

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Thanks Dmitrij. If I get this right, this is a code-only solution right? You wouldn't see in the job that those columns are mapped? Would it be an option to create an "Add column" feature in the job that gives you an empty input you can map to a new target column?

Imar

 

You must be logged in to post in the forum