Skip to end of metadata
Go to start of metadata

Script Overview

On the 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 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.

OCR should be running

Make sure that OCR is up and running before script execution. You can enable it on the Components tab.

Environment

  • Windows OS that meets System Requirements
  • Any of these browsers: Google Chrome or FireFox
  • MS Outlook (a version doesn't matter) with the 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

In this document:

Script Variables

Variable name

TypeDescriptionDefault value
input_files
Listthe list used to store the list of input files
ocred
Booleanthe flag used to check whether input file was processed or notfalse
contacts
Tablerequired to collect recognized contacts and then insert into file
folder_path
Stringthe path to the folder with input files (images)
login
SecretSalesforce username (need to be set up before script running)
password
SecretSalesforce password (need to be set up before script running)
contacts_error
Tablerequired to collect non-recognized contacts and insert into a separate file
url_sf_login
StringSalesforce login pagehttps://login.salesforce.com/
url_sf_contact
StringSalesforce Contacts pagehttps://ap5.lightning.force.com/one/one.app#/sObject/Contact/list?filterName=all
verification_code
Stringrequired 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. In case no template for a business card is found, the file information is added into a separate file.

ActionDescriptionImage
Get Folder ContentsIn this action, 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.

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

The steps are needed to open a .png file via the default viewer. The Wait action is required to give time to open the file and load the image.

Constant Value

Before processing each image file, the ocred flag and temporary variable contact are cleaned up.


Bot checks which predefined template is used in the separate file.

IF-ElseThe template check group starts with checking the ocred flag. If the condition is true, bot starts to process a specific file. In case it is false, it goes to the next template.

Wait for ImageBot waits for the 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.

IF-Else

If the template is found, bot processes with the contact recognition.

Exception Handling

OCR

When the template is found, bot can extract needed data using the OCR action.

Exception Handling is added to process with different screen resolutions, as OCR functionality is sensitive to image quality.

Exception Handling

OCR

Trim Whitespace

Expression Value

The actions are added to 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 will be reflected as a dash in the output.

Constant Value

Expression Value
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
If none of the predefined template is found, the file name is added to the list of non-recognized images and stored in the contacts_error Table variable.

Enter KeystrokesAt the end of the input file processing, bot closes the opened file with the key combination Alt + F4.

Export recognized contacts to .csv file

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

ActionDescriptionImage

Bot creates a file named out.csv in the path mentioned in the folder_path Table variable. If the file already exists, it will be overwritten.

For Each

Constant Value

Replace Text

Write to File

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

  • each row reads to temp variable text
  • square brackets are removed from the start and the end of row
  • the formatted row is written to the out.csv file


Script
REUSABLE

The custom script helps to add the end-of-line character (\n) at the end of each row.

How to reuse

You can easily use this script in other projects. For this, you just need to change the file name (here, out.csv) to any convenient name.

Open and upload data to Salesforce

Description: The group allows to log into Salesforce account with two-factor authentication and upload the .csv file into Salesforce contacts. The whole block can be used in other projects, no specific changes are required.

How To Reuse

To reuse the group, make sure you have added the required Salesforce credentials in Secrets Vault in WorkFusion StudioIf you add another Secret Vault entry, change the following variables:

  • login Salesforce username (Secrets Vault > Key)
  • password Salesforce password (Secrets Vault > Value)

ActionDescriptionImage

The group of actions opens the Salesforce login page mentioned in the url_sf_login variable. Then, bot enters Salesforce credentials that should be set in Secret variables as login and password. The Wait action is added for complete page loading.

Salesforce sends a verification code to the email that is set in the Salesforce user account.

  1. Bot opens the Run dialog with the key combination Win + R and calls Outlook.
  2. In Outlook, it searches for the email with the specific subject "Verify your identity in Salesforce".
  3. Bot opens the last email with this subject and searches for the verification code using the Wait for Image action.
  4. When the code is found, bot recognizes and saves it to the verification_code variable, and then closes Outlook.
  5. Bot returns to the browser and enters the verification code by 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.

Outlook view

Bot will find the verification email if the Outlook view is configured as below:

  • Reading Pane is on the Right side
  • Show as Conversations is unchecked
  • There is only one mailbox in the Outlook that should be linked to the Salesforce account.

On entering the verification code on the Salesforce page, bot opens the Contacts page with the All contacts option, clicks on the Import button, and uploads the out.csv file from folder_path. Then, it confirms the mapped fields and presses the Start import button.

  • No labels