Developer forum

Forum » Integration » How to add a mapping in a TableScript

How to add a mapping in a TableScript

Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

I would like to dynamically add a mapping in a table script. It comes up often, but the situation I have today is to set the OrderSecret on an order if it's not already set. (I'll separately submit a feature request for the Ecom provider to do that automatically since it's a standard field). 

I would like to not have to create a dummy mapping in the job for it, and rather, would like to create the mapping on the fly.

I thought I was getting close, but now the error I'm running into is "Column 'OrderSecret' does not belong to table EcomOrdersTempTableForBulkImport2.". So the AddMapping method seems to add the mapping, but it doesn't add the field to the temp table.

Here's the code I have so far:

var newSourceColumn = new Column("OrderSecret", typeof(System.String), mapping.SourceTable);
var newDestinationColumn = new Column("OrderSecret", typeof(System.String), mapping.DestinationTable);
mapping.AddColumnsFromSourceToMappingIfMissing = true;
mapping.AddMapping(newSourceColumn, newDestinationColumn);
mapping.GetColumnMappings().FirstOrDefault(c => c.DestinationColumn.Name == "OrderSecret").ScriptType = ScriptType.Constant;

I hoped that the AddColumnsFromSourceToMappingIfMissing property may cause it to be created, but that didn't seem to make a difference.

Since there is a AddMapping() method, I assume that it's possible to do.

Thanks,

Scott


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Scott,
That is because the temp tables are created before the table script is processing the importing rows, so you need the mapping for a destination column for its existence in the temporary tables columns.
Regards, Dmitrij

 
Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

Hi Dmitrij,

 

Ok, thanks for explaining the reason. It's not too bad, but it just would have been a bonus to be able to create columns in the table script. At least I understand why. Thanks.

Scott

 

You must be logged in to post in the forum