2 weeks ago
Hi Team,
I have written some customized code in code stage it requires the following packages
System
System.Collections.Generic
System.Data
System.Linq
I have added the references but i am getting the error in Initialize page.
can you please help on this.
Page: Initialise
Stage: Stage1
Type: Error
Action: Validate
Description: Compiler error at top section line 586: Type or namespace definition, or end-of-file expected
Repairable: No
No error in Code stage
Sample code:
success = true;
error_message = string.Empty;
filteredTable = new DataTable();
summaryTable = new DataTable();
var allowedTypes = new HashSet<string>
{
"ABC", "ABC"
};
var filteredRows = inputTable.AsEnumerable()
.Where(row => allowedCreativeTypes.Contains(row.Field<string>("Type")));
filteredTable = inputTable.Clone();
2 weeks ago - last edited 2 weeks ago
Could you please help me with your Inputs and outputs added in the code stage? what are the data types?
From the above c# code your trying to filter the data table but to filter data table Blue Prism already providing the Filter Collection action in Collection Manipulation VBO
This is Similar to your C# code and here Collection referred as Data Table .
Inputs:
Collection
Filter Expression - You can write your filter expression here
Outputs:
you can save the Output in same collection (which is nothing but same data table).
If you specifically trying with c# code to achieve this kindly help me with all your Inputs and Output parameters in Code stage.
2 weeks ago
Please try the below approach
Code:
// Initialize success flag and error message
success = true;
error_message = string.Empty;
// Create new DataTables for storing the results
filteredTable = inputTable.Clone();
summaryTable = inputTable.Clone();
// Define the allowed creative types (use a List<string> or string array)
List<string> allowedTypes = new List<string> { "ABC", "DEF" }; // Modify as needed
// Loop through each row in the input table to filter based on "Type" column
foreach (DataRow row in inputTable.Rows)
{
// Check if the "Type" column value is in the allowedTypes collection
if (allowedTypes.Contains(row["Type"].ToString())) // This uses List.Contains() method
{
// If it matches, add the row to the filteredTable
filteredTable.ImportRow(row);
}
}
Please let me know if the above works for your requirement.
Note: You can pass the inputTable as a Startup parameter from the process to object.
2 weeks ago - last edited 2 weeks ago
@faheemsd
It's not working below is my complete code along with all details. I feel some issue with dependent packages when i am compiling the code stage no errors were found.
This is not related to only filtering the collection, doing some operations using group by according to my use case which is not available in normal collection manipulation.
Code:
Inputs:
Outputs:
Packages:
Let me know if you need anything.
Thanks