Skip to main content
Version: 10.3.1

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:

  1. Install:
    • Work.AI Developer
    • Chrome or Firefox
    • MS Outlook with an email account configured and logged in providing a bot with the option to send emails
  2. 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.
  3. Make sure that OCR is running before script execution.
  4. Download the example.

Getting started

To get started, perform the following actions:

  1. Extract the sample folder and drop it into your default workspace in Recorder: C:/Users/name/workfusion-workspace/rpae_project.
  2. Open the sample in Recorder.
  3. Go to Window > Preferences, expand WorkFusion Recorder, and select the Secrets Vault tab.
  4. Press the Add button and enter salesforce_cred as Alias. Enter the Salesforce username in the Key column and the Salesforce password–in Value.
  5. Press Apply and Close.
  6. 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.
  7. Click Play recording.

Script overview

On a high level, the script consists of the following actions.

  1. Open and recognize business cards from image files according to predefined templates.
  2. Collect all recognized contacts and non-recognized data into CSV files: out.csv and out_error.csv.
  3. Log in to Salesforce and verify your Salesforce account via Outlook.
  4. 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 nameTypeDescriptionDefault value
input_filesListList used to store the list of input files
ocredBooleanFlag used to check whether the input file was processed or notfalse
contactsTableRequired to collect recognized contacts and then insert into file
folder_pathStringPath to the folder with input files (images)
loginSecretSalesforce username (need to be set up before script running)
passwordSecretSalesforce password (need to be set up before script running)
contacts_errorTableRequired to collect non-recognized contacts and insert them into a separate file
url_sf_loginStringSalesforce login pagehttps://login.salesforce.com/
url_sf_contactStringSalesforce Contacts pagehttps://ap5.lightning.force.com/one/one.app#/sObject/Contact/list?filterName=all
verification_codeStringRequired 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.

  1. In the Get Folder Contents action, a bot gets the list of PNG files from the folder mentioned in the folder_path variable and saves the results into the input_files List variable.

  2. In the For Each loop, files from the list are checked according to the existing templates. The recognized information is stored into the contacts Table variable, non-recognized–into contacts_error.

  3. 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.

  4. Before processing each image file, the ocred flag and the contact temporary variable are cleaned up. (Constant Value)

  5. The bot checks which predefined template is used in a separate file.

  6. The template check group (IF-Else) starts with checking the ocred flag. If the condition is true, the bot begins to process a specific file. If it is false, it goes to the next template.

  7. 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 true and is saved into the found variable.

  8. If the template is found (IF-Else), the bot processes with the contact recognition.

  9. 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.

  10. 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 contact temporary 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.

  11. On processing the file successfully, the ocred flag is set up as true, and the recognized information is added to the contacts Table variable (Constant Value, Expression Value).

  12. If none of the predefined template is found, the filename is added to the list of non-recognized images and stored in the contacts_error Table variable (Constant Value, Expression Value).

  13. At the end of the input file processing, the bot closes the file with the Alt+F4 key combination (Enter Keystrokes).

Export recognized contacts to CSV file

Description: The group exports successfully recognized contacts to the output CSV file.

  1. The bot creates a file (Create File or Folder) named out.csv in the path from the folder_path Table variable. If the file already exists, it is overwritten.

  2. In the For Each loop, all the recognized contacts are processed from the contacts row by row:

    • Each row reads to the text temporary variable.
    • Square brackets are removed from the start and the end of the row.
    • The formatted row is written to the out.csv file.

    The For Each, Constant Value, Replace Text, and Write to File actions are used.

  3. 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 Recorder. If you add another Secrets Vault entry, change the following variables:

  • login: Salesforce username (Secrets Vault > Key).
  • password: Salesforce password (Secrets Vault > Value).
  1. 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 theurl_sf_login variable. Then, the bot enters Salesforce credentials that should be set in secret variables as login and password. The Wait action is added for complete page loading.

  2. Verify your Salesforce account (reusable). Salesforce sends a verification code to the email that is set in the Salesforce user account.

    1. The bot opens the Run dialog with the Win+R key combination (Enter Keystrokes) and calls Outlook.
    2. In Outlook, it searches for the email with the specific subject "Verify your identity in Salesforce".
    3. The bot opens the last email with this subject and searches for the verification code using the Wait for Image action.
    4. When the bot finds the code, it recognizes and saves it to the verification_code variable, and closes Outlook.
    5. 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.
  3. 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 (Mouse Click) the Import button, and uploads the out.csv file from folder_path. Then, it confirms the mapped fields and presses the Start import button.