Put a function in a configuration file value

I am currently changing a bot to a different system, this bot has a Config file where I save paths to folders within the system. I would like to know if it is possible to place a function within the settings of the config file. Since for example my routes are saved as C: \ Users \ NAME_USER \ Documents \ myfolder, and I would like instead of having “NAME_USER” to have the function “system.Environment.UserName”, to be able to make this user change simpler. Is it possible to do this? And if so, what would be the correct structure to write it?

Here is few ideas for your concepts. The details are below:-

  1. You can save path like this file_path= “C: \ Users \ @@NAME_USER \ Documents \ myfolder”
  2. Anyway you are getting this path as a string, right?
  3. Assign activity name_user= “ system.Environment.UserName ”,
  4. Use string replace concept before you going to use the path in your flow
    file_path= file_path.replace("@@NAME_USER",name_user)
  5. final output will give valid file path. In future, If you move this file into different system. It will work
1 Like

The thing is that I only wanted to modify the config file and not touch the bot’s code since I call the routes on several occasions, but thanks for the suggestion!

Did you try with excel vba for this?

Maybe try like this

image

image

This is my workaround

Do it like this…

C:\Users{USERNAME}\Documents\myfolder

Let’s say that value is in a string variable named myPath. Then you just do…

String.Replace(myPath,"{USERNAME}",system.Environment.UserName)

You can’t put the function into the Excel spreadsheet. Replace is the correct solution, and it’s only a minor change to the code.