Lookup Data Table function with data table name as variable


I’m trying to do a Lookup Data Table activity but where the Data Table name is a variable. The activity is inside a loop and the lookup will occur in one of many possible tables. When I put in a variable to the Data Table field i’m told with an error that the input must be a datatable and not a string. Does anyone know how to resolve?

Thank you



Use the Assign activity to create a variable that represents the DataTable you want to perform the lookup on.
Inside the Assign activity, use the DataTable variable with the AsEnumerable method to specify the DataTable’s name.

Suppose you have a DataTable name stored in a variable called DataTableName , and you want to perform a lookup in that DataTable:

Assign DataTableVariable = If(DirectCast(Variables(DataTableName), DataTable), New DataTable())

Thank you for the quick response. Very confused how i use this?

I tried to put this into an assign block but i get an error that “Variables is missing”

I have a variable called temp1 that contains a string with the datatable name in it currently.

You can’t do this in UiPath. You can’t have a variable name stored in another variable. What you need is a dictionary (of string, datatable). Put all your datatables in with the datatable name as the dictionary key. Now you can get the datatable you want using yourDictVar(temp1)

Great idea! - thank you Paul - this worked

1 Like

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