[PowerShell] Monitor active log files in Windows using type -wait command

Oh this is super handy. Say you have an active log file you want to monitor in real-time, simply run this command in Windows Powershell and see your logs update live on the terminal.


To demonstrate, in the screenshot above, I simply created a script that logs the current timestamp every two seconds on a logfile located at the Desktop. Then I used Powershell to monitor the updates on the terminal.

To do so, simply open Windows PowerShell on your machine and run the following command:

type -wait "logfile.txt"

:)
Share:

[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:

[UIPath] How to use Regex String Matches Activity to extract capture groups

The Matches activity is a helpful way to extract parts of a string using regex patterns. If you're new to capture groups, it's essentially a regex pattern that allows you to get values in between specified characters.


For instance, this pattern "\[(.*?)\]" allows you to get all values in between square brackets.

This means that for this string example,

Email Assignment: [2574] The UK votes to leave [EU]. What's next?

there are two matches (highlighted). These two values are stored in a collection of matches with type IENumberable<Match> To get the first match, you can use: Matches(0).Value
This will get you [2574]

But if you only need the value inside the brackets, you still need to clean-up the string in order to remove the brackets.

Now, a much simpler way to extract the first match without the brackets is by using the Match.Groups method.

Using the same example above, if I use: Matches(0).Groups(1).Value
It will return just 2574

Matches(0) will return the first match: [2574]
And Groups(1) will return the first group in the match: 2574
Groups(0) on the other hand would return the whole matched string: [2574]

So essentially, Matches(0).Groups(1).Value will return the first group in the first match.
If you want to get EU instead, you should use Matches(1).Groups(1).Value

You may experiment with regex using UiPath's built in Regex Builder (Inside Matches activity, click Configure Regular Expression) or you can go to regexstorm.net/tester online.
Share:

[UiPath] Append Line not working when run using Robot or Orchestrator

Problem:
My log file isn't being created when I'm running the workflow using the robot, even if the path I supplied is already its full path. But then it's working fine when it's being run using the Studio.


Solution/workaround:
Create the log file first before appending to it (using the Create File activity). Normally, UiPath would automatically create the file if it doesn't exist, and then append some line. But for some reason when it's UiPath Robot doing the activity, the file doesn't get created, so UiPath doesn't bother writing anything.

That's it, let me know if it helps! :)
Share:

[UiPath] Helpful DataTable methods and queries for better sorting, filtering, extracting

Here are a couple of handy DataTable.Select queries that I found useful in managing data tables. I have previously discussed about How to filter multiple dynamic values in a datatable column but this time I'm going to collect my most used ones for future reference. I found this VB.net methods extremely helpful in minimizing the amount of Activities in my Workflow. Also, sometimes the Filter DataTable Wizard doesn't work and I found these methods more accurate.

How to select distinct/unique values in a column

OutputDT = DataTable.DefaultView.ToTable(true,"ColumnName")

Returns a datatable with distinct values from a specific column. This is similar to running a Remove Duplicate Rows activity except you can directly specify which column to affect.

How to rename DataTable column name

DataTable.Columns(4).ColumnName = "New Column Name"

Renames the 3rd column with the value specified in "New Column Name"

How to sort DataTable using multiple columns

DataTable = (From x In DataTable.AsEnumerable() Order By convert.Tostring(x("ColumnName1")), convert.ToString(x("ColumnName2")) Select x).CopyToDataTable

Returns a data table sorted in ascending order by 2 columns. This is similar to running a Sort Data Table activity except that you can use multiple sorting columns.

How to query your DataTable using Select method

OutputDT = DataTable.Select("[Column Name] IN ('Value1', 'Value2', 'Value3')").CopyToDataTable

This will return rows where the specified column contains the indicated values. Similar to filtering a table from Excel.

How to convert a DataTable column to a String Array

StringArray = (From row In DataTable.AsEnumerable() Select Convert.Tostring(row(“Column Name”))).ToArray()


This returns a String array containing all values in a given column

RelatedHow to filter multiple dynamic values in a datatable column

Just a few so far but will add to these as I go along learning UiPath better! :)
Share:

[UiPath] How to create Windows user input form using SyForms form designer (IsClosingForm hotfix)

Here's an entry on how to use the SyForms Form Designer package on UiPath which is incredibly helpful in getting user input using a Windows form.

This answers questions on:
✔ How to accept date input from user and
✔ How to accept multiple inputs from user using just one form


But first, a little info on this package:

SyForms is a custom activity developed by Florent Salendres of Symphony as a hackathon entry for UIPath's Power Up Automation 2018. It won Winners Choice and UiPath Grand Prize of Excellence in RPA and is probably one of the most popular form designers from UiPath Gallery. I personally am very thankful I stumbled upon this activity because it provides better user interaction by the way of Windows forms.

Now, all the official documentation you need is here: https://go.uipath.com/component/syforms-uipath-forms-designer
https://devpost.com/software/uipath-form-designer
https://forum.uipath.com/t/syforms-uipath-forms-designer/63539/29

But for the purpose of documenting a how to guide, here's how to use the package and create a simple form that accepts date and text input.

I'm using UiPath Community Edition version 19.8.0

Step 1: Download and install the package

You have two options, you can either download it from the Gallery


OR you can download the hotfix version from this link which addresses the issue of the form not closing upon clicking the submit button (even if the property IsClosingForm is set to True).

If you chose the hotfix version, here's how to install it:

  1. As mentioned above, download hotfix from this link
  2. Save the .nupkg package file under C:\Users\username\AppData\Local\UiPath\app-19.8.0\Packages (or wherever your Packages folder is)
  3. Update the path with the appropriate username and app version folder, in red.
  4. Go back to UiPath Manage Packages and navigate to Local. Symphony should appear.
  5. Install and Save



Step 2: Create a new process and add the activity Show Form

Found under Symphony >> Extensions >> SyForms >> Show Form



Step 3: Create a new form

  1. Click on New
  2. Enter form name
  3. Click OK
  4. It will create a json file. Select it from the dropdown and click Design
Step 4: Design the form

We'll be creating a simple form that accepts Name and Birthday. The designer is pretty straightforward, just click on the type of control you want from the toolbar and position it on the form window.


Step 5: Expose your input arguments

For all your input fields, make sure to set ExposeAsArgument property to True as seen in the above photo. This automatically creates arguments for your fields so that you can access the value later on.


The next thing to do after exposing your arguments is to create Assign To variables to it. I named the 2 variables as var_name and var_bday and set the variable type to Control (System.Windows.Forms.Control).

For the Submit button, you should also set the IsClosingForm property to True so that the form window will close after you click on Submit.

Step 5: Access your input data

Finally, you can access your input data by using the Text property of the Control variable.

var_name.Text
var_bday.Text

Let's try to output it using a message box.

Here's the output:


For the date, you can play around with the text value to output different date formats using the Convert.ToDateTime() and ToString() System methods.

ie.
Convert.ToDateTime(var_bday.Text).ToString("yyyy-MM-dd")
will output the following:


For more DateTime formats and helpful string manipulation techniques, check out:

That's it! Let me know if it works. :)
Share:

[UIPath] How to filter multiple dynamic values in one column using DataTable.Select method

I've been looking for ways to filter multiple values in a datatable but I'm only led to one solution, the Select() method. For those who were sold on UIPath being a drag-and-drop-no-coding-required solution to automation, this could be intimidating. Heck, if I didn't know about SQL I'd be dead beat right now. Yup! The only way (at least for now) to select multiple values from a column in a datatable is by using the DataTable.Select method.

Thankfully, it's not that hard.

RelatedHelpful DataTable methods and queries for better sorting, filtering, extracting

Say I have this datatable called rulesDT,



And I want to get all rows where Home Location is either London, Manila, or Tokyo

If only UIPath had a feature like this in its Filter DataTable activity, it would be easy right?

UIPath wishlist: Allow IN operation

But since there's none at the moment, here's what worked for me.

Using DataTable.Select()

var rows = new DataRow[]; //Array of DataRow

var outputDT = new DataTable;

assign rows = rulesDT.Select("[Home Location] IN ('London','Manila','Tokyo')");

//Check if there are results
if(rows.Count > 1){
   outputDT = rows.CopyToDataTable();
} else {
   //Do something
}

The pseudo code above, when applied as a UIPath workflow, will return a datatable with rows that satisfy the query, in this case 5 rows.


It's similar to running a filter rule on MS Excel.

The reason we need to assign the results to a DataRow[] first instead of directly putting the output into DataTable is to avoid running into this exception in case there are 0 rows found. 


You cannot copy 0 rows to a DataTable, that's why we need to check first if the Select query returned at least one result.

Example for querying multiple columns

I want to get Partners between the ages 30 to 40 years old

rulesDT.Select("[Occupation] = 'Partner' AND [Age] >= 30 AND Age <= 40")
There is no BETWEEN operator so we have to use two comparators.

Querying dynamic values

If you want to select multiple dynamic values from a column, you need to build the parameters first then include it as a variable.

•  Using a list of integer

var rows = new DataRow[]
var dynamicIntArr = {20,30,40}
var join_dynamicIntArr = String.Join(",",dynamicIntArr) //Result: 20,30,40
rows = rulesDT.Select("[Age] IN (" + str_dynamicIntArr + ")")
•  Using a list of string
This requires more manipulation as you have to wrap each value inside single quotes. It would be best to prepare the string with single quotes beforehand for easier handling.

var rows = new DataRow[]
var dynamicStrArr = {"'One'","'Two'","'Three'"}
var join_dynamicStrArr = String.Join(",",dynamicStrArr) //Result: 'One','Two','Three'
rulesDT.Select("[Age] IN (" + join_dynamicStrArr + ")")

Very helpful links

Share:

How to make an HTML modal window using Javascript and CSS

This is basically an application of this tutorial from w3schools. I've created a fiddle for it and customized mainly the CSS.

Modals are a neat way to present content in an HTML page without making it look cluttered. You can use it to contain information you don't want to be visible at all times. You increase the usability of your website by not having your user jump to a new page for small information or a form.


This is really more of a note to self haha but hope you find is useful too!
Share:

[UIPath] How to include default Outlook signature dynamically in Send Outlook Mail Message activity

How nice would it be if UIPath would enhance its Send Outlook Mail Message activity to allow users to include their default email signature?

Something like this...

UIPath wishlist: looking forward to this feature enhancement!

Photo is edited of course hehe but in the meantime that's it's not possible directly, here's a pretty neat workaround I've discovered.
But first, here's the situation. I have a robotic workflow that sends email messages on Outlook, and it's being run by multiple users, depending on who's available. Naturally, the email will be sent from their personal accounts, so the signature must be theirs as well.

I need a way to automatically fetch their signatures as HTML and attach it to the email body. The challenge for different users is that the signature details are different as well, so you have to generate the appropriate ones every time you run the robot.

One way would be to prepare a text file containing a signature template and have them edit the details every time they run the workflow. You can then read this text file and append it to the email body.

But another, more straightforward way is to fetch their signature files directly from Outlook's directory.

Somewhere in your user account's roaming folder is your outlook email signatures. These are the email signatures you've created using your mailbox. In my case, they're stored here:

C:\Users\<username>\AppData\Roaming\Microsoft\Signatures


The folder structure may differ per setup but if you're working with users within the same network or have the same MS Office setup, chances are the path is the same, except for the username of course. And you can get that using the Environment.username variable.

So now that you have the direct path to your Outlook's default email signature, you know the rest. Read it, store it in a text file, and finally append it to your message body. Don't forget to tick IsBodyHtml! :)


Caveat? Images don't work, so there's that.

Hope this helps somehow!
Share:

[UIPath] VBA macro for formatting headers in Excel

Here's a neat piece of code I use whenever I needed to apply a macro that formats headers on an Excel workbook. I always come across this step whenever I write a datatable to an Excel file. Datatables are being copied as plain text so you have to format it to make it look more presentable. The goal is to programmatically turn this unformatted workbook...


to a formatted one which is very much readable and ready for reporting:


Here you go:

Private Sub FormatHeaders()
    Dim ws as Worksheet
    For Each ws in Worksheets
        ws.Activate
        Cells.EntireColumn.Autofit
        Cells.EntireRow.Autofit
        Rows("1:1").Font.Bold = True
        Range(Range("A1"),Range("A1").End(xlToRight)).Interior.Color = RGB(173, 216, 230)
    Next
    Sheets(1).Select
End Sub

What this macro does is loop through all the sheets in the workbook and do the following:
  • Autofit all columns
  • Autofit all rows
  • Bold the headers
  • Add background color to the headers
Then it will focus back on the first sheet.

Now it's easy to read and ready to sent out. Remember to setup MS Excel's trust settings if you're going to run an external macro.

Hope this helps!
Share:

[UIPath] Error: Could not connect to UiPath Robot Service. Make sure the service is started!

I'm encountering this error a lot these days, I'm not sure why. But for some reason this error only appears when I'm running a workflow that was created using an older version of UiPath. When I try to run the workflow on Studio, it gives me this message:


As suggested by the prompt, I made sure that the UIRobot service is started. But it still doesn't work. Restarting the service doesn't work either unless it's done in the following order (see below). So here's how I got through this error:


1. Close UiPath Studio
2. Run services.msc (win + R >> services.msc)
3. Look for UiPath Robot service
4. Stop UiPath Robot service (right click >> stop or look for the stop button on the toolbar)
5. Open UiPath Studio and load the workflow you want to run
6. Start UiPath Robot service (right click >> start of look for the start button on the toolbar)
7. Run the workflow on UiPath Studio

That should do it! Hopefully it works for you too :)
Share:

[UIPath] How to schedule robotic workflows without Orchestrator

Note: Task Scheduler execution is no longer supported since version 2017.1 
(source: https://forum.uipath.com/t/unattended-robots-w-or-w-out-orchestrator/18534/5)

An alternative to UIPath Orchestrator that we've found effective in scheduling robotic processes is Windows built-in Task Scheduler. We got the idea after learning that workflows can be run from the command line.


The concept is simple, first you create a script that starts a robotic process using UIPath robot. Then, you create a new task on Task Scheduler, load that batch file as an Action, and set your desired schedule.

Here's how:
Creating the script file

Open notepad and type the following command:

"C:\Program Files (x86)\UiPath\Studio\UIRobot.exe" 
/file:"C:\Users\Yan\Scripts\UIPath\ExcelTest\ExcelTest.xaml" /executor /monitored
  • Replace the first location with the actual path of your UIPath Robot
  • Replace the second argument with the actual path of your xaml workflow
  • Save the file as a .bat file

Creating the task

Open up Task Scheduler and Create a Task.
  • On the Actions tab, add the script file you created
  • On the Triggers tab, setup the schedule you want for this task
That's it! The general idea is to be able to use Task Scheduler for running scheduled workflows instead of UIPath Orchestrator. I don't know the specifics about setting up a task but we only configured Triggers and Actions tab for this. 

:)
Share:

[Windows] How to open multiple apps at once using the run dialog

Basically what I want to do is launch several applications in one command. There are many options to do this. You can create a batch file that opens several applications then run it, or you can simply type a command from the run dialog that launches the apps you want.

I choose to do the latter because it's easier for me.

Here's the syntax. Suppose I want to launch Notepad, Calculator, and Task Manager in one go:


cmd /c start notepad & start calculator & start taskmgr
  • This command basically tells the computer to execute the program followed by the start command. 
  • The & allows you add multiple commands.
  • Remember to use the program's process name in order to launch them properly
Share:

[UIPath] Error: Programmatic access to Visual Basic Project is not trusted

If you encounter this error on UIPath saying "Programmatic access to Visual Basic Project is not trusted", it could mean that your MS Excel's Macro Trust Settings is disabled.


By default, Excel blocks any programmatic access to the application unless the user permits it. You may be invoking an external VBA macro file in your UIPath workflow that's causing this error. To enable trust settings, simply do the following:

  1. Open a blank workbook on MS Excel
  2. Got to File >> Options
  3. Click on Trust Center >> Trust Center Settings


  4. Click on Macro Settings >> Check ‘Trust Access to the VBA project object model’ (under Developer Macro Settings)


  5. Click OK to exit Trust Center window >> Then Click OK again to exit Excel Options window
Let me know if it worked! :)
Share:

[UIPath] Helpful VB expressions for date, string, and array/collection values

Here are my most commonly used VB expressions for handling date, string, and array/collection values. Will add more to these as I go along. UIPath activities essentially use VB.NET expressions so their API browser is extremely helpful in learning functions and syntax. .NET API Browser:
https://docs.microsoft.com/en-us/dotnet/api/?view=netframework-4.7.2

String

How to print new line on Message Box
Use vbCrLf
ie. "Hello" + vbCrLf + "World"

How to concatenate string and variable values
Use + operator
ie. "My name is " + var_name

How to split string value based on delimiter
Use the Split method to split a line of text into array values based on a delimiter
ie. Split("apple~bear~cat~dog","~") will return an array with 4 values.

To access them, you can loop through the array or for smaller and more defined formats you can simply retrieve the value based on its index number.

Split("apple~bear~cat~dog","~")(0) returns "apple"
Split("apple~bear~cat~dog","~")(1) returns "bear"
Split("apple~bear~cat~dog","~")(2) returns "cat"
Split("apple~bear~cat~dog","~")(3) returns "dog"

How to combine all array values into a string
Use the Join method
ie. var stringArray = {"Apple","Bear","Cat"}
String.Join("/",stringArray) will result to "Apple/Bear/Cat"

How to trim leading and trailing spaces from a text
Use the Trim method
ie. Trim("     This is a sentence    with lots of spaces.    ")
Note that Trim() removes only the spaces at the start and end, not the inside of the string.

How to replace certain characters in a string
Use the Replace method
ie. "apple~bear~cat~dog".Replace("~","!")
Replaces all instances of ~ with !, so that leaves me with "apple!bear!cat!dog"

Date/Time

How to format date value
Use ToString method
ie. Now.Date.ToString("MMMM yyyy")
will give to the current date displayed in this format: January 2018

For other custom date and time formats:
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

How to convert string value to DateTime format
Use Convert class
ie. Convert.ToDateTime("January 31, 2019")

For more details about the Convert class:

How to get first day of the month
Use the Date function and just format the day value as 1
ie. Now.Date.ToString("MMMM 1, yyyy")
will get you January 1, 2019

How to get last day of the month
Use AddMonths method to get the first day of the next month, then subtract 1 day using the AddDays method. 
ie. Convert.ToDateTime(Now.Date.ToString("MMMM 1, yyyy")).AddMonths(1).AddDays(-1).ToString("MMMM d, yyyy")
Will give you January 31, 2019 (relative to date today)

Note that you have to convert the first day of the month back to DateTime in order for the AddDays and AddMonths method to work.

Array/Collections

How to get all files in a folder
Use Directory.GetFiles method
ie. Directory.GetFiles("C:\Data\UIPath","*.*",SearchOption.AllDirectories) 
returns a String array of all the files inside the UIPath\ folder, including its subfolders, that matches the search pattern indicated in the 2nd argument.

"*.*" basically takes all types of files. "*.pdf " will get only files with the .pdf extension.
SearchOption.AllDirectories searches even the subdirectories under UIpath\

Because this method returns a String array, use a For loop to run through the collection.

For more info:
Share:

[UIPath] How to use Filter in Get Outlook Mail Messages Activity

The Filter property in Get Outlook Mail Messages allows you to set a filter for the messages to be retrieved from the specified mail folder.


Note that the Filter argument is for STRICT filters only. Meaning, wildcards and regex matches won't work. For example:

This filter retrieves messages received on the current month:
[ReceivedTime] >=' + Now.ToString("MM/01/yyyy") + "' AND [ReceivedTime] < '" + Now.AddMonths(1).ToString("MM/01/yyyy")+ "'"

This filter retrieves messages with the EXACT subject line 'Manila Downtime Advisory'
[Subject]='Manila Downtime Advisory'

Click here for more filter arguments you can use.
Share:

[UIPath] Extract value inside parenthesis using regex patterns

I have a scenario here where I wanted to extract a value inside a parentheses. Using the Matches activity in UIPath, I'm able to do just that. Here's how: Look for Matches activity and drop it on your workspace. I added a Message Box below to see the output.


On the Properties panel, fill in the Input (string) and Pattern (regex). For the Result, create a new variable with data type IEnumerable<Match>. This will hold all the matches found in your string input.


Input: "I want to extract (value) here"
Pattern: "\((.*?)\)"
Result: RegexMatch (var with DataType IEnumerable<Match>)

Since I know I'm only looking for 1 match, I don't need to loop through the result array. I can simply access the first value by checking index 0, hence RegexMatch(0).ToString in the Message Box.

This will output the following:


Knowledge of regular expressions is needed here, thankfully there's Google! If you want to validate your regex before running the activity, you can use this link: http://regexstorm.net/tester
Share: