cancel
Showing results for 
Search instead for 
Did you mean: 

How to update Environment Variables from batch file

MuralikrishnaPe
Level 2
HI Team,

I have created batch file to import environment variables from bot but am not able to set Date and Datetime Also i need help on passing the JSON text from batch file  how can i pass (Date, Datetime & JSON text) from bat file to update environment variables

Thanks & Regards,
P Murali.

------------------------------
Muralikrishna Perewar Module Lead
Module Lead
Mindtree
Asia/Kolkata
------------------------------
6 REPLIES 6

ewilson
Staff
Staff
Hi @MuralikrishnaPe,

I don't believe we expose an object or API for setting the value of environment variables. There's an action available on AutomateC utility for deleting environments variables, but nothing that I see for creating. So it seems you have two options:

1) You could read your batch file in using regular BP objects such as the Utility - File Management VBO. Then you could use the Data - SQL Server​ VBO to connect directly to the Blue Prism database and update the specific environment variables using SQL. The table of interest would be BPAEnvironmentVar.

2) The other option would be to create a UI automation for the actual Interactive Client, so you would create the necessary application model for starting the Interactive Client, navigate to System -> Processes -> Environment Variables or System -> Objects -> Environment Variables and perform the update of the variables via the UI.

Hope that helps.

Cheers,


------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

david.l.morris
Level 15
Looks like Eric has already addressed a couple options you have, so I'll just mention what else I can think of. If I remember right, I had the same issue with certain datatypes such as Date and DateTime when setting Environment Variables via AutomateC. I believe it's a bug, and now that I think about it, I should probably submit that as a bug so Blue Prism is aware of it. I've never tried using AutomateC to update an environment variable that would contain JSON. I usually only had simple text. Since then, I've pretty much stopped using Environment Variables, and we use CONFIG files now for each automation. So that's something else you could consider if you're allowed to. The processes can just pick up a text file with JSON in it.

Also, @ewilson, for creating and updating environment variables via AutomateC, the command or switch is /setev <name> <datatype> <value> <description>. This is a second thing I'll go ahead and submit a bug for. The list of AutomateC commands in the Help documentation using F1 (which is now online) doesn't show the full list of commands/switches available. The only way to see them all is to use the "AutomateC /help"​ command in CMD. I only know this because it was a project I was playi...I mean...working on a couple years ago and randomly decided to compare the list of commands shown in F1 compared to the AutomateC help output.

So, just fyi, I'll be submitting a bug for the /setev command regarding that it doesn't seem to work for date and/or datetime, and I'll also submit a bug regarding the command list difference. Eric, if you have a direct inroad to submit bug info, lemme know and I can cancel my ticket as soon as I see you've got it taken care of.

------------------------------
Dave Morris
Cano Ai
Atlanta, GA
------------------------------

Dave Morris, 3Ci at Southern Company

@Dave Morris I think the product guys are more inclined to listen to you than me. 😂

Cheers,
​​​

------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Hahaha! Fair, I may or may not have heard that same feedback. 😃

Looks like I spoke too soon anyway. I went back, and it seems that I am smarter than my past self and I just tried a few different string formats for inputs to setting date and date time. Here's a batch script that works for date, datetime, time, timespan, text, number, flag, password:

Ok, so it's super important that you get the strings EXACTLY in the right format when setting these. If you set one of these Date/Time-related environment variables incorrectly, your Environment Variables screen will look like below. Don't worry though. First, don't test this in a shared environment for the first time. Second, if this happens, you can delete the environment variables from the database pretty easily and no harm has been done.
8080.png
Now that the warning is out of the way. It seems I cannot choose Batch as a language type for this code below. Don't be fooled. It's not VB even though I chose that. 😃 I left the username and password in the script on purpose. If anyone is reading this who isn't familiar with Batch or AutomateC commands, replace the "dave" values with your actual username and passwords if it's Blue Prism Native authentication. If you're using Blue Prism at an enterprise level, then you're probably using SSO. Replace "/user %username% %password%" with "/sso" if you authenticate with SSO.

Example: 
AutomateC /sso /setev "Sample Date Env Var" "Date" "2021-10-14" "Test Description"

Anyway, here's the script for anyone who is having issues with setting certain environment variable datatypes by AutomateC. Just copy the text into a text file and rename the file to have a file extension of .bat.
set username=dave
set password=dave

cd /d "C:\Program Files\Blue Prism Limited\Blue Prism Automate"
AutomateC /user %username% %password% /setev "Sample Date Env Var" "Date" "2021/10/14" "Test Description"
AutomateC /user %username% %password% /setev "Sample DateTime Env Var" "DateTime" "2021-10-14 20:59:59Z" "Test Description"
AutomateC /user %username% %password% /setev "Sample Time Env Var" "Time" "23:59:59" "Test Description"
AutomateC /user %username% %password% /setev "Sample TimeSpan Env Var" "TimeSpan" "7.23:59:59" "Test Description"
AutomateC /user %username% %password% /setev "Sample Text Env Var" "Text" "Test Value" "Test Description"
AutomateC /user %username% %password% /setev "Sample Number Env Var" "Number" "42.42" "Test Description"
AutomateC /user %username% %password% /setev "Sample Flag Env Var" "Flag" "True" "Test Description"
AutomateC /user %username% %password% /setev "Sample Password Env Var" "Password" "Secret" "Test Description"
PAUSE

Note that the Date and other formats are possibly a regional thing. I have no idea. But, I believe the best thing for you to do is to create environment variables in the UI first, and then go look at the values in the database using SSMS and that will show you the exact format that the strings need to be in for them to be interpreted correctly.

------------------------------
Dave Morris
Cano Ai
Atlanta, GA
------------------------------

Dave Morris, 3Ci at Southern Company

Hi Dave,

You mentioned you are using config file instead of  using update envr variable in automate c . I was curious, how is this config file looks like ..it contains only environment variables  or any other variables.

I have seen other RPA vendors are using similar approach  ( using config files.. for  max retry, url.....) and I  haven't tried using config file but was aware of using  that.

Thanks,

------------------------------
Harish Mogulluri
developer
Ics
America/New_York
------------------------------
-----------------------
If I answered your query. Please mark it as the Best Answer

Harish Mogulluri

Hi Harish,

As per my experience, you can have a variety of configuration file formats. It also depends from client to client and organization to organization. I will give few examples from my past clients. I have come across automations where clients have used Excel files, XML files, JSON files, Text Files as well as SQL Server Database to create a separate configuration table.

Excel File Configuration:

When we talk about excel configuration, you can probably have different sheets fro 'DEV', 'QA' and 'PROD' with three columns in each one of them such as Name, Value and Description. This configuration file path and the sheet which needs to be accessed can be stored in the Blue Prism Environment Variable section. This way even let say you process has 70 configurable variables to manage, the complexity on your environment variable end is way less as you just have to maintain the file path and sheet name properly.

For fetching the values, you can probably create a collection out of these columns and use filter collection action to fetch any desired variable. An alternate approach would be to create a custom code stage that can transpose the Name and Value column in such a way that the names of the collection become the headers and the values for each of these names become a value in a single row. This way you can treat your collection as a dictionary variable: [Collection_Name.Name] will give you that specific value only.

XML Files:

You can create an XML file with a node structure such as the following:
<config>
   <env name="DEV">
        <name_1>value_1</name_1>
        <name_2>value_2</name_2>
        <name_3>value_3</name_3>
   </env>
   <env name="QA">
        <name_1>value_1</name_1>
        <name_2>value_2</name_2>
        <name_3>value_3</name_3>
   </env>
   <env name="PROD">
        <name_1>value_1</name_1>
        <name_2>value_2</name_2>
        <name_3>value_3</name_3>
   </env>
</config>

You can go ahead and parse this structure to get all the related values in a collection by using the XPath Expression along with the Get Attribute action from Blue Prism to get the elements under the exact environment name which you can get from your Environment Variable.

JSON File:

You can use a sample JSON file as well to create an array of values which can be parsed directly into a datatable using JSON To Collection action.

[
{"Name_1":"Value_1"},
{"Name_2":"Value_2"},
{"Name_3":"Value_3"}
]

Text File:

You can even create a sample text file where every file might consist of a separator in between the names and values in multiple lines. You can read the lines into a collection and then by using a split action for each of that line you can populate an already created collection with two columns : "Name" and "Value" with the relevant data from each line. For example:

Name_1=Value_1
Name_2=Value_2
Name_3=Value_3

Database Tables: You can create a separated SQL table as well with the same structure as shown in excel files, have three columns : Name, Value and Description. Make a SQL Query from Blue Prism to get Name and Value into your collection.


Conclusion is that no matter what approach you take, think of having a collection data with two columns where one can be referred as a key and another as a value and from there you will be able to fetch it using either filter action or by using a custom transpose which can generate a single row collection with names as headers and values as the corresponding field values for that collection.

------------------------------
Regards,
Devneet Mohanty
Intelligent Automation Consultant
Blueprism 6x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com
------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.