Search

How to create an RPA Flow using OneDrive activities to upload documents

Overview

This tutorial will show you how to create a basic flow using few of the OneDrive activities. We will create a flow to upload the documents/ files into OneDrive Folder by reading them first from the outlook account. We will be using For Each File or Folder in combination with Get Files or Folders to upload the document to an already existing folder.

Note: The For Each File or Folder in combination with Get Files or Folders can be also replaced by Find Files or Folder as shown in this tutorial: How to Create an RPA Flow Using OneDrive Activities to Download Files.


Components

  • RPA Management
  • RPA Studio
  • OneDrive access (MS Office 365)
  • Outlook email account

Requirements

  • Before you can start building the flow, you’ll need to install RPA Studio on your machine and set up a connection between the RPA Studio and RPA Management. Check the Infor RPA Studio User Guide for the steps on how to do it.
  • Create the RPA Application in Azure tenant following the steps listed in: Register an application with the Microsoft identity platform – Microsoft Graph | Microsoft Learn
  • Create the MS Office 365 Oauth provider in RPA Management
  • Authorize the application in RPA Management
  • Note: All the above steps are part of the RPA User Guide
  • Create a folder on your local drive called Attachments having the following path: C:\RPA\Attachments
  • Create OneDrive folder called: Demo_RPA_Onedrive_Write

Tutorial

Difficulty: Hard
Estimated completion time: 45 Minutes

Note : In order to avoid flow failure, user must authorize MSGraph in the RPA Mastermind Dashboard to use Graph related Activities.

1. Open RPA Studio on your machine. If you are not signed in already into the Tenant you will be asked to sign in before proceeding to RPA flow designer screens.

2. On the Home page of RPA Studio click Create New Project and specify the following properties in the popup window:

  1. Name: OneDrive Upload Share
  2. ProjectLocation: <default>
  3. Description: OneDrive flow to get the mails from mail outlook and upload to OneDrive Folder
  4. Language: VB <selected by default>

3. We will start the flow by adding a Sequence block to create a small sub-flow to read the mails from the outlook account and store the attachments. Drag and drop the Sequence activity from the Activities side panel. 

4. Next in the Activities panel, look for Get Outlook Emails Graph, which allows to read the mails from Outlook Account in MS Office 365. Click on the activity on the design canvas and set up its properties. Create few arguments which can be references to the activity properties.

  • Note: To use this activity and OneDrive activities you need to create OAuth provider MS Office 365 as listed in pre-requisites.
  • Select the Include Attachments property
  • Mail Folder Name property should contain the name of the mailbox folder from where we will read the email. Create an Argument called MailFolderName of type: string and default value: ”demo”   
  • Select the Mark as Read property.
  • For Retrieve Top N Mails you can specify e.g. 3
  • For Email List  we can create a variable instead of the argument. This variable will store the list of the email read from the outlook account.
    • called mailList of type: List<Mail> without any default value
      • to find List <Mail> data type expand the Variable Type and select Browse for type. In the Type Name cell type List and select List under the System.Collection.Generic domain. Once selected, below the System.Collection.Generic.List from the dropdown select Browse for type and in the new dialog window in the Type Name cell type Mail and select Mail under Infor.Activities.Email.Mail.

5. Now, we will create a loop which will allow us to save an attachment from each read mail. For that we need to add For Each activity and specify the following:

  • for Type property as Mail ( Infor.Activities.Email.Mail) which is same as a single object type from the mailList variable
  • for value property define mailList.
  • In the activity on Design Canvas You will see the following text “Foreach item in mailList” the item signify the single object in this example mail within the list of object, here list of mails

6. Within the Body first add a Sequence.

7. Next, add Download Email Attachment Graph activity which will allow us to save the attachment from each of the read mails. Specify the following properties:

  • For Email property specify Item as in For Each activity
  • For Save Destination which is a path of the directory where the attachment should be stored, create argument:
    • called attachmentFiles of type string and default value “C:\RPA\Attachments”
  • For File Paths output property create a variable
    • called paths of type List <String>
      • to find List <String> data type expand the Variable Type and select Browse for type. In the Type name cell type List and select List under the System.Collection.Generic domain. Once selected, below the System.Collection.Generic.List from the dropdown select the String and click ok.
  1. Now, we will add the activity Get Files Directory which will allow us to read all the attachements we stored on the local system. The activity can be access in Activities panel under System category. Drag and drop the activity on the deign canvas and click on it. The properties of the selected activity will appear in the properties panel. Let’s configure its properties in a following way:
  • for Path, which is the path of a specific directory from which we would like to read the files specify attachmentFiles variable which we used for saving the attachements.
  • for Files, which the list of files path read in the directory, let’s create a variable:
    • called FileList_attachements of type List  <string> without any default value
      • to find List <String>data type expand the Variable Type and select Browse for type. In the Type name cell type List and select List under the System.Collections.Generic domain.
      •   this variable will store the list of the file paths
  1. Next we will add the For Each Files or Folders, which will allow us to list the ids of one or multiple folders/ files based on the defined Query. Let’s configure the activity in following way:
  • For Search Keywords which is the keyword based on which we will be looking up folder(s)/ File(s), create argument:
    • called OneDriveWrite of type string and default value “Demo_RPA_Onedrive_Write”
  • For Account which is OneDrive Account from where we will be looking up OneDrives Ids, create argument:
    • called AccountMail of type string and default value of you mail
  • For Limit Results specify 1, as we want to only find 1 folder
  • For Results which will store the array of the retrived IDs, let’s specify the variable
    • called resultID of type String []
  1. Next we will add the Get File Or Folder which retrieves a single OneDrive object based on provided Id, you will find it also under One Drive category in activity panel. Select the activity and configure in the following way:
  • For OneDrive Item ID which is the id of the id to retrieve specify the variable resultID in a following way resultID(0) so only a first item from array will be retrieved
  • For Account which is OneDrive Account from where we will be looking up OneDrives Ids, create argument:
    • called AccountMail of type string and default value of you mail
  • For Item which is the OneDrive item retrived, let’s specify the variable
    • called Folder_OneDrive of type OneDriveItem
  1. Now we will be sharing the created OneDrive folder which we found. For that lest add Share File or Folder into the canvas. Click on the activity and configure it in the following way:
  • For  File or Folder to Share property which should contain the id of the OneDrive Item to share specify Folder_Onedrive variable output from Get File Or Folder activity.
  • For  Grantee permissions select which permissions should a person you share the file with get. You can select between Edit and View.
  • For Grantee Type which is the type of the recipient for whom the permission are granted, you can select from dropdown e.g. SpecificPeople, PeopleInOrganization or Anyone
  • For Recipients which is the list of people with whom we should share the folder, let’s create the argument
    • called reclist of type Array of string, String[] without a default value(s) written between the “{}” e.g. {“natalia.ptaszek@infor.com“, “john.smith@infro.com“}
  • For Require sign in select True
  • For Send sharing invitations mail select True
  1. Next we will create a loop which will allow us to upload each of the stored attachment into OneDrive Folder For that we need to add For Each activity and specify the following:
  • for Type property as String which is same as a single object type from the FileList_attachements variable
  • for value property define FileList_attachements.
  • In the activity on Design Canvas You will see the following text “Foreach item in FileList_attachements” the item signify the single object in this example mail within the list of object, here list of file paths

Note: Optionally next you can add the Sequence activity inside of the For Each block

  1. At the end add Upload File to start uploading the attachments saved in the File directory on the local system and specify the following properties of this activities;
  • For File Upload property specify Item as in For Each activity
  • For In Case of a Conflict select Replace
  • for Destination Folder define the variable Folder_Onedrive
  • for Destination Path, which is the path of the uploaded file or folder, let’s create the variable:
    • called attachementDrive of type OneDriveItem without any default value

Now the flow is complete and can be run to read the files and upload them to one drive automatically.

Activities List