[UiPath] How to setup config file and read variables

Updated December 2019
I just figured there's something wrong with my implementation of the config file, specifically its file location. The path needs to be absolute otherwise the robot package will refer to the config file inside the nupkg file and you would need to re-publish the workflow every time you update the config file.

---

Setting up a config file for your workflows is an efficient way to configure the initial settings of your workflow environment. Variables that refer to path locations, URLs, and other config information that you need to setup when moving your workflow from one environment to another are better placed inside a config file. Think of it as not having to go inside UiPath studio to update your variables every now and then. Instead, you can just create a config file in Ms Excel, and read it in your workflow.

Here's how:

1. Create your config file

In this example, I named the config file as FileConfig.xlsx.
You can place it anywhere actually, just take note of its absolute path. It's the only path you'll put inside your workflow.



2. Set your variables using two columns



Variable names on Column A, then values on Column B.

3. Read your config file and store it in a DataTable

Use the Read Range (Workbook) activity to read the config file and store it in a DataTable.

4. Access your config variables using the DataTable.Select method



var config_var = DataTable.Select("[Column Name]='variable name'")(0)(1).ToString


Use the select method to return the row that matches the variable name in the Var column of your config file, and (0)(1) index to refer to the second column of the first matched row. 

That's it!

If you need to add more config variables on the excel file, you should likewise add another Assign activity in your workflow to fetch the new variable.

Hope this helps!
Share: