Contacts recognition and upload to Salesforce
Example overview
Problem statement
When you meet people at some conference or another public activity, they give you their business cards, but you don't have much time to look at and remember all of these people. Still, you can store cards in your pocket or wallet and look at them and sort out needed contacts after some time. Then, perhaps, you want to save all the contacts to your enterprise CRM system to further make business with these people.
Existing manual process
Usually, you need to manually enter contacts from all your cards into your system. It's not a big deal in the case of a few cards, but if you have dozens of them every day, it becomes a routine that takes time. Our sample provides an approach showing how to automate this manual task.
Automation solution
A bot processes existing cards stored in the PNG format according to predefined templates. After that, all the recognized contacts are collected in a CSV file to be uploaded to Salesforce. Unrecognized contacts not associated with any existing templates are collected into another file for manual check. The bot uploads the recognized contacts using a specific Salesforce account with two-factor authentication.
Reusable components
In this example, there are three reusable components:
- Log in to Salesforce.
- Verify a Salesforce account.
- Upload a file to Salesforce.
Preconditions
Before you start working, ensure all the requirements are met:
- Install:
- WorkFusion Studio (IA Cloud Developer)
- Chrome or Firefox
- MS Outlook with an email account configured and logged in providing a bot with the option to send emails
- To play the sample, you need to have a Salesforce account that should be linked to your account in MS Outlook to receive a verification code via email.
- Make sure that OCR is running before script execution.
- Download the example.
Getting started
To get started, perform the following actions:
Extract the sample folder and drop it into your default workspace in WorkFusion Studio:
C:/Users/name/workfusion-workspace/rpae_project.Open the sample in WorkFusion Studio.
Go to Window > Preferences, expand WorkFusion Studio, and select the Secret Vault tab.
Press the Add button and enter
salesforce_credas Alias. Enter the Salesforce username in the Key column and the Salesforce password–in Value.
Press Apply and Close.
Copy input files from the folder images to an appropriate folder and edit the following variables:
folder_path: the path to the input files with business cards images.
Click Play recording.
Script overview
On a high level, the script consists of the following actions.
- Open and recognize business cards from image files according to predefined templates.
- Collect all recognized contacts and non-recognized data into CSV files:
out.csvandout_error.csv. - Log in to Salesforce and verify your Salesforce account via Outlook.
- Upload the CSV file with recognized contacts to Salesforce.
Let's explore these steps in detail.
caution
Make sure that OCR is up and running before script execution.
Environment
- Windows OS that meets System Requirements
- Any of these browsers: Google Chrome or Firefox
- MS Outlook with an email account linked to your Salesforce account to receive a Salesforce verification email
- Screen resolution should be one of these:
- 1920 x 1080
- 1900 x 600
- 1366 x 768
- 1280 x 1024
- 1024 x 768
Script variables
| Variable name | Type | Description | Default value |
|---|---|---|---|
input_files | List | List used to store the list of input files | |
ocred | Boolean | Flag used to check whether the input file was processed or not | false |
contacts | Table | Required to collect recognized contacts and then insert into file | |
folder_path | String | Path to the folder with input files (images) | |
login | Secret | Salesforce username (need to be set up before script running) | |
password | Secret | Salesforce password (need to be set up before script running) | |
contacts_error | Table | Required to collect non-recognized contacts and insert them into a separate file | |
url_sf_login | String | Salesforce login page | https://login.salesforce.com/ |
url_sf_contact | String | Salesforce Contacts page | https://ap5.lightning.force.com/one/one.app#/sObject/Contact/list?filterName=all |
verification_code | String | Required to store Salesforce verification code |
Script workflow
Process input files
Description: The group opens input files with images, recognizes business cards, and stores information into temporary Table variables. If no template for a business card is found, the file information is added into a separate file.
In the Get Folder Contents action, a bot gets the list of PNG files from the folder mentioned in the
folder_pathvariable and saves the results into theinput_filesList variable.
In the For Each loop, files from the list are checked according to the existing templates. The recognized information is stored into the
contactsTable variable, non-recognized–intocontacts_error.

The Launch Application and Wait steps open a PNG file via the default viewer. The Wait action provides time to open the file and load the image.


Before processing each image file, the
ocredflag and thecontacttemporary variable are cleaned up. (Constant Value)
The bot checks which predefined template is used in a separate file.

The template check group (IF-Else) starts with checking the
ocredflag. If the condition istrue, the bot begins to process a specific file. If it isfalse, it goes to the next template.
The bot waits for the image (Wait for Image) that is specific for each predefined template. If the image is found on the screen, the result becomes
trueand is saved into thefoundvariable.
If the template is found (IF-Else), the bot processes with the contact recognition.

When the template is found, the bot can extract needed data using the OCR action. Exception Handling is added to process different screen resolutions, as the OCR functionality is sensitive to image quality.

The Exception Handling, OCR, Trim Whitespace, and Expression Value actions are added to the format recognized information and used to:
- Remove unnecessary whitespaces.
- Add the value to the
contacttemporary variable. - Populate the company name and phone number for a specific template.
In this specific template, there is no phone number on the business card image, so the phone number is reflected as a dash in the output.

On processing the file successfully, the
ocredflag is set up astrue, and the recognized information is added to thecontactsTable variable (Constant Value, Expression Value).
If none of the predefined template is found, the filename is added to the list of non-recognized images and stored in the
contacts_errorTable variable (Constant Value, Expression Value).
At the end of the input file processing, the bot closes the file with the
Alt+F4key combination (Enter Keystrokes).
Export recognized contacts to CSV file
Description: The group exports successfully recognized contacts to the output CSV file.
The bot creates a file (Create File or Folder) named
out.csvin the path from thefolder_pathTable variable. If the file already exists, it is overwritten.
In the For Each loop, all the recognized contacts are processed from the
contactsrow by row:- Each row reads to the
texttemporary variable. - Square brackets are removed from the start and the end of the row.
- The formatted row is written to the
out.csvfile.
The For Each, Constant Value, Replace Text, and Write to File actions are used.



- Each row reads to the
The custom script helps to add the end-of-line character (
\n) at the end of each row (reusable).tip
To use this script in other projects, change the filename (here,
out.csv) to any convenient name.
Open and upload data to Salesforce
Description: The group allows logging into a Salesforce account with two-factor authentication and uploading the CSV file into Salesforce contacts. The whole block can be used in other projects, no specific changes are required.
To reuse the group, make sure you added the required Salesforce credentials in Secrets Vault in WorkFusion Studio. If you add another Secret Vault entry, change the following variables:
login: Salesforce username (Secrets Vault > Key).password: Salesforce password (Secrets Vault > Value).
Log in to Salesforce (reusable). The group of actions (Exception Handling, Open Website, Maximize Window, Constant Value, Switch to Browser, Web Element, Enter Keystrokes, Wait) opens the Salesforce login page used in the
url_sf_loginvariable. Then, the bot enters Salesforce credentials that should be set in Secret variables asloginandpassword. The Wait action is added for complete page loading.
Verify your Salesforce account (reusable). Salesforce sends a verification code to the email that is set in the Salesforce user account.
- The bot opens the Run dialog with the
Win+Rkey combination (Enter Keystrokes) and calls Outlook. - In Outlook, it searches for the email with the specific subject "Verify your identity in Salesforce".
- The bot opens the last email with this subject and searches for the verification code using the Wait for Image action.
- When the bot finds the code, it recognizes and saves it to the
verification_codevariable, and closes Outlook. - The bot returns to the browser and enters the verification code using XPath.

Exception Handling is added to process different Outlook versions. The Wait action is added to give the page time to load all its content.
caution
The bot finds the verification email if the Outlook view is configured as below:
- The Reading Pane is on the right side.
- Show as Conversations is unchecked.
- There is only one Outlook mailbox linked to the Salesforce account.
- The bot opens the Run dialog with the
Upload output file to Salesforce (reusable). On entering the verification code on the Salesforce page, the bot opens the Contacts page (Open Website) with the All contacts option, clicks (Click Mouse) the Import button, and uploads the
out.csvfile fromfolder_path. Then, it confirms the mapped fields and presses the Start import button.