Map Input Columns to Output Columns using Dictionary Expression

Hi team,

Here is the dictionary expression that I am using to map columns in the input file to columns in the output file. There are a couple of extra columns that need to be hardcoded.

New Dictionary(Of String,String)From{{“Business Unit”,“Business_Unit_ID”},{“Article #”,“Style_id”},{“Color Id”,“Color_id”}, {“Rank, (KLM Product)”, “Rank”}}

Example 1: I’ve “App Module” Columns that need to be populated by “STYLE” for all the rows under that column.

Example 2: I’ve “Created By” Columns that need to be populated by “fetene.ronald@example.com” for all the rows under that column.

Thanks for your help.

Hi @Sisay_Dinku

How about the following?
Assign it to a MyDyct Var

New Dictionary(Of String, String) From {{"Business Unit", "Business_Unit_ID"}, {"Article #", "Style_id"}, {"Color Id", "Color_id"}, {"Rank, (KLM Product)", "Rank"}, {"App Module", "STYLE"}, {"Created By", "fetene.ronald@example.com"}}

Regards!

@fernando_zuluaga
Just to clarify a little bit more. “STYLE” and “fetene.ronald@example.com” are values to be added into the output columns which do not have corresponding columns from input file. “App Module” and “Created By” columns do not exist in input file.

It sounds like you should be using a datatable not a dictionary, since you need multiple values for each not just two values (key/value).

@postwick

Thank you for your response. Can you elaborate a little more? If you could, example please!
Thanks

Answer by fernando_zuluaga is correct. For hardcoded columns , you can add some special character in key which would tell your code to use hardcoded value in dictionary value instead of searching in excel columns e.g. key : “app module_fixedvalue”

@Sagar_1986

Thank you!
Can you rewrite the expression? I want to understand how you can add the hardcoded values.
New Dictionary(Of String,String)From{{“Business Unit”,“Business_Unit_ID”},{“Article #”,“Style_id”},{“Color Id”,“Color_id”}, {“Rank, (KLM Product)”, “Rank”}}

after adding these values
Hardcoded Values Destination Columns
STYLE → “App Module”
fetene.ronald@example.com → “Created By”

I am sorry that I do not I fully understood. Thanks for your help.

New Dictionary(Of String,String)From{{“Business Unit”,“Business_Unit_ID”},{“Article #”,“Style_id”},{“Color Id”,“Color_id”}, {“Rank, (KLM Product)”, “Rank”},}{“Rank, (app module _fixedvalue )”, “fetene.ronald@example.com”}

In code check if dictionary key contains (“_fixedvalue”)
If yes use dictionaryitem.value directly instead of trying to find columns

Not an elegant solution but will work

A dictionary only allows two things in it - it’s key/value pairs. You can have a key and a value. It’s generally intended that they key is the “name” and the value is the value although it’s technically possible to use it the way you are - to store two values. But you need more than two values for each item. With a datatable you can have as many columns as you want for each item, like a spreadsheet.

Hi @Sisay_Dinku

Can you try this-

Assign dictionary = New Dictionary(Of String, String) From {{“Business Unit”, “Business_Unit_ID”},
{“Article #”, “Style_id”},
{“Color Id”, “Color_id”},
{“Rank, (KLM Product)”, “Rank”}}

’ Example 1: Add hardcoded value “STYLE” for “App Module” column
dictionary(“App Module”) = “STYLE”

’ Example 2: Add hardcoded value “fetene.ronald@example.com” for “Created By” column
dictionary(“Created By”) = “fetene.ronald@example.com

Thanks!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.