April 17, 2019

Automating expense reporting with robotic process automation

By

Theta

Automating expense reporting with robotic process automation

Nobody likes entering expenses into their company’s business management system, so we decided to tackle the frustration head on. How could we make expense reporting faster? Better? Funner? (ok maybe that’s not a word but you know what we mean!). Could robotic process automation help?

The problem with expense reporting

Theta’s current expense reporting process takes ages and involves:

  • Scanning each receipt
  • Noting down each receipt’s basic details, billing location, category, location, total amount
  • Converting currency, if the total amount isn’t in NZD
  • Entering the details into an expense report
  • Changing the receipt image filenames according their details
  • Uploading all receipt images as attachments to the report

There had to be a better way.

Robotic process automation applied to expense reporting

UiPath is an application for building automation workflows and Taggun is an API which reads receipts and extracts the basic data from them, so we no longer have to. Together, they might help.

Our main goal: Total automation of expense entering and ZERO interaction with Autotask.

Taggun does most of the grunt work for processing receipt data, expertly grabbing the Date, Amount, Currency Type, Address and Merchant from receipts. Only the Category and Description are left up to the user’s discretion.

We created two main workflows:

  • Process the receipts and push the data received to an Excel spreadsheet
  • Take the expense data from the spreadsheet and automate entering each expense into Autotask.

Processing receipts workflow

The user provides the file location where all their scanned receipts are stored, the month they would like to create the expense report for and then we obtain the user’s name through Autotask using UiPath’s text scraping activity.

We then send each individual receipt through the Taggun API and process the data received. This is achieved using custom activities which can be created using .NET Framework. Create a .NET Framework project and a class within it, this will become a custom activity. We then implement the CodeActivity class (from System.Activities) on the class we have just made and make use of RequiredArgument attribute from System.Activities and the Category attribute from System.ComponentModel as shown below:

An example custom activity

The execute function (implemented from the CodeActivity class) houses all the logic for the custom activity. To use the activity in UiPath we build the project and bundle its dll file into a NuGet package with its relevant dependencies. Each class within the project represents a custom activity that can be called within UiPath. We found this tutorial on bundling class libraries into a local NuGet package helpful.

Excel automation

UiPath comes with most of the functionality built in to automate tasks in Excel, such as reading/writing to a range in a spreadsheet, appending rows and so forth. We ran into our first major hurdle when we tried to create dropdown lists in Excel for expense category. We then realized we could mimic the act of creating a dropdown list through automation by directing UiPath to manually create a dropdown list, just like you normally would. With a conditional statement to check which button icon existed, we were on our way.

This sort of workflow is used throughout our automation processes, allowing us to differentiate between many different scenarios that could occur and handle them in a seamless way.

User validation

Between the two workflows, we need the user to validate the data received from the Taggun API calls in Excel. Users set the currency and category with the UiPath automated Excel dropdown lists, and tweak the description if required. Once all is validated, the user starts the second workflow, Automating Expense entry into Autotask.

Automating expense entry workflow

Automating expenses starts off with the user navigating to the newly generated Excel spreadsheet. Then we handle currency conversion.

Currency conversion is accomplished through a custom activity we created. We hook into a free API for currency conversion found here. The excel sheet provides the currency code i.e. “AUD” or “USD” and then we extract the “NZD” conversion rate and convert the amount we have in our excel spreadsheet to the newly converted amount, which will then populate with the newly converted values within the sheet.

Generating meaningful filenames for each receipt

We needed to figure out how to meaningfully rename each receipt processed, so they can be easily distinguishable for entry into Autotask. We ended up reading in the data processed for each receipt into a custom activity and doing some checks on the currency type, to see whether there was a converted amount or not.

Filenames are then generated for each receipt, with their date, category and amount. If there was a currency conversion this will be included too.

Once generated, we use a little trick with the “Move File” activity in Autotask, where we move the image to the same location, but with its newly generated name.

After this we move on to Autotask, where the first order of business is checking if the expense report we are in the process of making already exists.

We use another conditional statement to achieve this. We first use screen scraping to extract the rows from the table of current expenses within Autotask and check whether the one we are making exists. If it does, we use the built in Optical Character Recognition text click activity to click it, else we create a new report.

After this, UiPath starts automatically filling in expense report fields for each expense included in the excel spreadsheet.

The page for entering expense fields was tricky. We used UiPath’s image clicking activity to find each field label and added an offset in the Y axis from the image. We then used the offset to find the label’s input field to type into. Using this manoeuver, we were able to fill out all fields in the window.

We also had to construct conditional workflows for the category field as it changed the structure of the window, which we had to cater for.

The final step in the process is adding all the receipts for each expense as an attachment to the expense report. This required us to think about how we were going to find each image if we weren’t already operating within the file location of the images, and so we took the filename of the images and appended it to the file location of the images we got from process one, constructing the image path to find each image we needed to add.

What we learned from building an automation workflow

Receipts are extremely diverse in size, in form and details. This posed a problem for Taggun as it wasn’t able to decipher all receipts to the fidelity required. This problem was accounted for in a user validation step, so the data entered into Autotask is accurate and error-free.

Autotask is a prickly old thing and some creative thinking was needed to make UiPath and Autotask get along. We eventually conquered each obstacle by mastering the variety of inbuilt activities provided by UiPath. We have encountered success with OCR (Optical Character Recognition), text clicking, clicking images and using the built-in recording function in UiPath to get around more delicate issues.

We learned a lot by attempting to create an automation workflow. Along the way, as we became more aware of the possibilities of UiPath, we will slowly became more competent with solving most, if not all, unexpected complications. Sometimes a little bit of ingenuity was required.

The moral of the story

UiPath is great tool for creating simple or even complex automation workflows. It’s flexible enough to allow custom activities, plus has a substantial library of built-in activities that can be manipulated to suit your needs. If you find a process mundane and time consuming, you can probably automate it with UiPath, saving you a lot of time in the long run.

Where to next?

We are currently looking at other processes that could be easily automated at Theta to save everyone time. Timesheets are top of the list. We're also interested in hearing from customers interested in applying this or other emerging technologies to business problems they face