The Collection package in the SmartDesigner acts as a container for users and robots to store information / data during run-time.
Add to Collection
Activity Name |
Picture |
AddToCollection |
|
When to use the Add to Collection activity
If you want to dynamically store the data from an Excel file or a web service in a table format for further processing, you can use this activity.
Figure 1.0
|
S.no |
Description |
1 |
Define the data type of the variable as ICollection<T> |
|
2 |
Display Name property shows the action that the activity performs in the workflow |
|
3 |
The item property helps you define the data that needs to be iterated logically |
|
4 |
TypeArgument specifies the datatype of the input stored in the collection. |
Declare a new variable in the Variables section by selecting "browse for types" in the Variable Type drop-down and entering the type name as ÔÇ£System.Collections.Generic.ICollection.ÔÇØ Then choose String from the type drop-down. (Refer figure 1.1, 1.2, 1.3 & 1.4)
Figure 1.1
Figure 1.2
Figure 1.3
Figure 1.4
Since the input data is a string. The TypeArgument should be defined as String. However, the TypeArgument can also be Boolean, Integer and Array[t] based on the requirement.
TypeArgument provides multiple datatype to choose from.
Select the datatype based on the variable declared for the collection.
Assume you want to collect information about employees who have been working in your organization for more than ten years. All employee details are available in an excel sheet for this illustration.
Create an Excel file with the required data of the employees for this purpose.
Activity: Open the SmartDesigner tool and read the employee details from the Excel sheet using the ÔÇ£Excel AutomationÔÇØ activity. Store the information to build the data table using an Add to Collection activity.
LetÔÇÖs start building a robot
Step 1 ÔÇô Open the SmartRPA Designer tool
Step 2 ÔÇô Open a new workflow
Step 3 ÔÇô Look for ÔÇ£ExcelAutomationÔÇØ grouping in the Toolbox, drag a ÔÇ£Read ExcelÔÇØ activity onto the workflow. (Refer figure 1.8)
Step 4 ÔÇô Go to the property section and fill in the details, give the FilePath Name by double clicking the activity and selecting the file from the respective folder or as an alternative, key in the file name in the FilePath property as a string(ÔÇ£ÔÇØ) e.g. "C:\Users\<username>\Desktop\Input.xlsxÔÇØ. and specify the sheet number to extract the data that needs to be executed.
- Right-click on the activity and click Set as Start Node. This implies that it will be the first activity that gets triggered during execution
- Select the process type as ÔÇ£Read till EndÔÇØ
- Key in both the Start Column & the Start Row field with value as 1
- Declare a new variable in the Variables section by selecting "browse for types" in the Variable Type drop-down and entering type name as ÔÇ£system.data.datatableÔÇØ (Refer figure 1.5, 1.6 & 1.7)
Figure 1.5
Figure 1.6
Figure 1.7
- Update the declared variable nameÔÇØ InputÔÇØ under the ÔÇ£OutDataÔÇØ field that contains the entire data, read from the Excel in a table format. (Refer figure 1.7)
Figure 1.8
Step 5 ÔÇô Drag a "For Each" activity from the Toolbox to iterate each item from the input file (Refer figure 1.9)
- Select the typeArgument as ÔÇ£System.Data.DatarowÔÇØ to iterate the input in a row sequence
- Fill ÔÇÿinÔÇÖ section with the variable name of the datatable appended with ÔÇ£.AsenumerableÔÇØ e.g. Input.Asenumerable
Figure 1.9
Step 6 ÔÇô Drag an ÔÇ£AddtoCollectionÔÇØ activity from the Toolbox
- Declare a new variable with the datatype as: :ÔÇ£System.Collections.Generic.ICollection<System.String>ÔÇØ and update the default section as ÔÇ£New list(of string)ÔÇØ under the variable section. (Refer figure 1.1, 1.2, 1.3 & 1.4)
- Key in the declared variable ÔÇ£AddÔÇØ in the Properties panel for the ÔÇ£CollectionÔÇØ property
- To iterate row/ input, key in ÔÇ£item(0).tostringÔÇØ in the string field. In this scenario it is defined as ÔÇ£item (3).tostringÔÇØ as we require employee experience from the Input excel to be processed
- Select the TypeArgument as ÔÇ£StringÔÇØ
Step 7 ÔÇô Drag an ÔÇ£Assign activityÔÇØ from the Toolbox. It is used to increment the counter value. This counter is used to dynamically retrieve the data from collection and to validate if the number of iterations has crossed the collection count (number of rows to be processed.)
- Declare a new variable with data type as "Integer" to capture the counter value under variables section (refer figure 1.10)
Figure 1.10
- Key in the declared variable under "To" Field, enter the variable name as ÔÇ£IÔÇØ and enter ÔÇ£0ÔÇØ in value field to increment the value
Step 8 ÔÇô Drag a ÔÇ£Flow DecisionÔÇØ activity from the Toolbox and define a condition based on the requirement to execute the flow. (Refer figure 1.13)
Count Validation
- Define the condition as "I<add.count" ÔÇô hence the bot will check if the counter value i. e "i" is less than add. count which contains the count of employees in the collection
- Under True branch, connect a ÔÇ£Flow DecisionÔÇØ activity and define a condition as Convert.toint32(add(i))>10. Here we are converting the string to integer since we receive the data from the data table as a string
- Under False branch, connect a ÔÇ£WriteLogÔÇØ activity to print ÔÇ£Process completedÔÇØ message, which denotes the completion of execution
- Drag a ÔÇ£Clear Collection" activity to clear the entire data in the collection. This part will be explained in the ÔÇ£Clear CollectionÔÇØ activity section
- Define the condition as ÔÇ£Convert.toint32(add(i))>10.ÔÇØ This condition checks if the employee experience is more than 10 years
- Under True branch, connect a ÔÇ£WriteLogÔÇØ activity to print the employee name with more than 10 years of experience.
Under False branch, connect a ÔÇ£Flow DecisionÔÇØ activity from the toolbox and apply a condition as ÔÇ£Convert.toint32(add(i)) <=3ÔÇØ. As per this condition, the bot will remove the data of the employees with work experience that is less than 3 years. This part will be explained in ÔÇ£Remove from collectionÔÇØ activity section.
Remove from Collection
Activity Name |
Picture |
Remove from Collection |
|
When to use the Remove from the Collection activity
This activity is used to remove certain data stored from the collection.
Figure 1.11 |
S.no |
Description |
1 |
Define the data type of the variable as ICollection<> |
|
2 |
Display Name property shows the action that the activity performs in the workflow |
|
3 |
Key in the value in item field to remove from the collection |
|
4 |
Declare the Boolean variable and update the variable name in ÔÇ£ResultÔÇØ field, it specifies if the data has been removed from the collection or not |
|
5 |
TypeArgument specifies the datatype of the input stored in the variable. |
Select the TypeArgument based on the variable declared in the ÔÇ£AddtoCollectionÔÇØ (refer figure 1.4)
In the aforementioned scenario, we stored the employee data of those who have worked for more than 10 years. Now, the requirement is to remove the employee data of candidates with less than 3 years of experience.
Activity: To remove data from the Collection, use the ÔÇ£RemoveFromCollectionÔÇØ activity.
Step 1 ÔÇô Drag a ÔÇ£RemoveFromCollectionÔÇØ activity and connect the activity to the True branch under the ÔÇ£Experience Validation decisionÔÇØ to remove certain data from the collection. (Refer figure 1.13)
- Go to the property section and fill in the details, enter the variable name as Add under ÔÇ£CollectionÔÇØ field which was already declared for ÔÇ£AddToCollectionÔÇØ process (Refer figure 1.4)
- Define the syntax as ÔÇ£add(i)ÔÇØ in the item field. This provides the employee experience and index number, i.e., data that the robot requires to validate
- The result field specifies if the data has been removed from the collection or not. Declare the variable type as ÔÇ£BooleanÔÇØ
- In the aforementioned scenario we selected the TypeArgument as "String". The same condition needs to be applied here to remove certain data.
Step 2 ÔÇô Drag a ÔÇ£WriteLogÔÇØ activity to print ÔÇ£Next EmployeeÔÇØ message and loop the flow to ÔÇ£Count validationÔÇØ decision, so that the flow executes in a loop to remove the data of employees below 3 years of experience.
Step 3 ÔÇô Drag an ÔÇ£Assign ActivityÔÇØ and connect the activity into the False branch. This counter is used to dynamically retrieve data from the collection and to validate if the number of iterations has crossed the collection count (number of rows to be processed.)
- Declare a new variable with type as "Integer" to capture the counter value under the variable section (Refer figure 1.10)
- Key in the variable name under "To" Field which was already declared for ÔÇ£AddtoCollectionÔÇØ increment and update ÔÇ£i+1ÔÇØ under value section to increment the value and loop the flow to ÔÇ£Count validationÔÇØ decision, so that robot will validate if the number of iterations has crossed the collection count (number of rows to be processed.)
Clear Collection
Activity Name |
Picture |
Clear Collection |
When to use the Clear Collection activity
This activity is used to clear all the existing data stored in the collection.
Figure 1.12 |
S.no |
Description |
1 |
Define the data type of the variable as ICollection<> |
|
2 |
Display Name property shows the action that the activity performs in the workflow |
|
3 |
TypeArgument specifies the datatype of the input |
Select the TypeArgument based on the variable declared in the ÔÇ£AddtoCollectionÔÇØ (Refer figure 1.4)
In the previous case, we stored the employee data of those who have been working for more than 10 years. From this, we removed the employee data of those who have less than 3 years of experience. Now, the requirement is to clear the data of employees with less than 10 years of experience in the organization from the collection.
Activity: To clear the entire data from the Collection, use ÔÇ£ClearCollectionÔÇØ activity.
Step 1 ÔÇô Drag a ÔÇ£ClearCollectionÔÇØ activity and connect the activity to False branch under the ÔÇ£Count ValidationÔÇØ to clear the entire data once the number of iterations has crossed the collection count. (refer figure 1.13)
- Go to the property section and fill in the details, enter the variable name as Add under "Collection" field which was already declared for ÔÇ£AddToCollectionÔÇØ process (Refer figure 1.4)
- In the aforementioned scenario we selected the TypeArgument as "String", the same condition needs to be applied here to clear the entire data from the collection.
The aforementioned scenario calls each Collection activity to perform the operation.
Figure 1.13
ExistInCollection
Activity Name |
Picture |
ExistinCollection |
When to use the ExistinCollection activity
When you want to indicate whether a given item is present in a given collection. This activity can be used.
Figure 1.14
|
S.no |
Description |
1 |
Define the data type of the variable as ICollection<> |
|
2 |
Display Name property shows the action that the activity performs in the workflow |
|
3 |
The item to search the specified collection for |
|
4 |
Gets or set the result argument. |
|
5 |
TypeArgument specifies the datatype of the input |
Select the TypeArgument based on the variable declared in the ÔÇ£AddtoCollectionÔÇØ (Refer figure 1.4)
Figure 1.15